Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

preproccessor error in IAR and codevison

Status
Not open for further replies.

naderus

Member level 1
Joined
Sep 7, 2004
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
213
codevision sizeof

Hi,
I want to write something like this in IAR or Codevision my code:

#define A sizeof(long)
#define B 100 - A
#if (A < C)
#error no
#endif

but when i compile it with IAR get this error:

Error[Pe059]: function call is not allowed in a constant expression

and when compile it with codevision get this error:

Warning: undefined symbol 'sizeof' , assumed zero
Error: missing ')'
( I get this error on line "#if (A < C)")


but when I write this code:

#define A sizeof(long)
#define B 100 - A

the IAR and codevision both are compiled without any error.
I also test it with MPLAB 7 that is for PIC and don't get any problem.
Can anyone tell me what is it wrong?It's really important for me that
write my code like it.
 

I've tested the code in codevision (old version, 1.2.37) and the error is because the sizeof function would be evaluated at runtime, but the #define argument should be constant!
If you replace "sizeof(long)" with 4, you won't get this error. (If A<C, of course you would get an error from the #error directive).

In codevision long is 4bytes, a constant, so you can just put 4. Evaluating sizeof would be usefull for portability.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top