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<stdio.h>
#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?

Edited 5 Years Ago by acechauhan: n/a

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:

#define ACECHAUHHAN_SECONDS_PER_HOUR 3600

More carefully

#ifndef ACECHAUHHAN_SECONDS_PER_HOUR
#  define ACECHAUHHAN_SECONDS_PER_HOUR 3600
#endif

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

This question has already been answered. Start a new discussion instead.