Can you use #defined values in if statements (In C programs)?
Posted
by Jordan S
on Stack Overflow
See other posts from Stack Overflow
or by Jordan S
Published on 2010-04-30T20:14:19Z
Indexed on
2010/04/30
20:17 UTC
Read the original article
Hit count: 198
I am new at C programming. I thought when you type something like #define Const 5000
that the compiler just replaces every instance of Const with 5000 at compile time. Is that wrong?
I try doing this in my code and I get a syntax error. Why can't i do this?
#define STEPS_PER_REV 12345
... in some function
if(CurrentPosition >= STEPS_PER_REV)
{
// do some stuff here
}
The compiler complains about the if statement with a syntax error that gives me no details.
© Stack Overflow or respective owner