View Single Post
  #10   Spotlight this post!  
Unread 06-01-2007, 00:14
prograid's Avatar
prograid prograid is offline
Registered User
AKA: Ben Cherian
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Oct 2004
Rookie Year: 2004
Location: San Jose
Posts: 80
prograid will become famous soon enough
Re: Why it works with an underscore?

Quote:
Originally Posted by Generalx5 View Post
Is it possible to define something and have a set of commands built into it?

Something like this?

#define Setting_1 ((solenoid1 = 1) && (Solenoid2 = 0) && (solenoid3 = 1) && (solenoid4 = 0) && (solenoid5 = 0) && (solenoid6 = 0));

will this allow me to do....

if (Sensors_are_online);
{
Setting_1
}


basically if the sensor receives a signal, it would turn on setting_1 which is to turn solenoid 1 and solenoid 3 on.
Yes, #define basically does a find & replace. However, it is a good practice to not have a semicolon at the end of a macro, that way, when you use the macro, it has a semicolon at the end of the line and keeps you from wondering whether you are missing any semicolons.

By the way, you don't need a semicolon after the if (Sensors_are_online) statement.

In general, any sort of construct that uses curly braces does not have a semicolon for itself. Rather, the individual statements within the braces have semicolons at the end of them.