Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#define

Status
Not open for further replies.

OOzy

Programmer
Jul 24, 2000
135
SA
Hi

what does this mean

#define ToRad(X) X*(PI/180)

does it mean like
int ToRad(X)
{
return X*(PI/180)
}
 
It just means

replace 'ToRad(X)' with 'X*(PI/180)' wherever you find it in the file except when it is within quotes (" ") or when it is within a comment (/* */ or //).

Its directed to the preprocessor, and occurs before the compilation actually begins. Ankan.

Please do correct me if I am wrong. s-)
 
It works similar to what u've written but all occurances of the macro are replaced even before compilation. for ex.
if u use ToRad(5) somewhere in ur program that gets replaced by 5*(PI/180). this type of macro function is not allocated any memory as it doesn't exist during compilation.
 
I think you should do:
#define ToRad(X) ((X)*(PI/180))
/*see ()*/ Ion Filipski
1c.bmp


filipski@excite.com
 
I agree with John, the extra parens will help you to avoid any Macro errors which are a PAIN to debug.

Matt
 
thats right, take the case
#define a(x) x*x

when u use 100/a(10), that becomes 100/10*10 & u get 100. so watch the ().
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top