Hi, I am just starting to code in C. While using the

#define sec 3600

the compiler returned an error - expected identifier or ‘(’ before numeric constant.

#define sec 3600
#include <stdlib.h>
int main(){
/*Rest of the code*/

If I change sec to seconds, the compiler does not return any errors and the program executes normally. I don't understand. Is sec a keyword or is predefined? Is there some rule about preprocessor directives that I am not familiar with?

Recommended Answers

All 3 Replies

macros do not honor any kind of scoping. Somewhere in the include files the token 'sec' is being converted to the manifest constant 3600. This is one reason that we have all agreed that macros will always be CAPITALIZED since that much reduces the chance of such conflicts. Better yet, make the macro your own so there is almost no chance of conflict; and while doing that, make it self documenting:


More carefully


between lines 2 and 3, you can force an error if you need your own macro and no other.

Right. Thank you.

which compiler you are using???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.