electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Logical Operators in ChucK
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jbum



Joined: Oct 24, 2006
Posts: 26
Location: Los Angeles

PostPosted: Fri Nov 03, 2006 3:20 pm    Post subject: Logical Operators in ChucK
Subject description: ...do not break off evaluation early, as in C...
Reply with quote  Mark this post and the followings unread

Just a word of warning to seasoned 'C' programmers out there...

I was using a conditional statement like this one, to do a sanity check on an array index:

Code:

// DOES NOT WORK AS I EXPECTED
if (n < ary.cap() && ary[n] < 5)
{
  // do stuff...
}



Assuming that, like in C, the second part of the && expression would not be evaluated if the first part failed. This doesn't actually happen - the code generates an out-of-bounds message regardless. To fix it, I used this:

Code:

// WORKS
if (n < ary.cap())
{
  if (ary[n] < 5) {
  {
     // do stuff...
  }
}

_________________
<a href="http://www.krazydad.com/">krazydad.com</a>
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Nov 03, 2006 9:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hmmmm, I see no advantage here in ChucK's behaviour over C, sounds like a good feature to have.
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use