Reputation:
I am trying to learn C and finding myself getting stuck a lot, no complains :)
Anyway, I wrote a program and GCC does not like it. The following code is NOT the program, but demonstrate the problem:
#define MAXLINE = 1000
int main()
{
int tmp = MAXLINE;
char line[MAXLINE];
return 0;
}
When it is compiled, I get the following error:
test.c:7: error: expected expression before ‘=’ token
If I replace symbolic constant MAXLINE with int 1000, everything works.
What is going on?
Upvotes: 2
Views: 472
Reputation: 108988
When the preprocessor replaces your definition of MAXLINE
, your code is changed to
int main()
{
int tmp = = 1000;
char line[= 1000];
return 0;
}
The C preprocessor is very dumb! Do not put anything extra in your #defines (no equals, no semicolons, no nothing)
Upvotes: 21
Reputation:
You shoud have
#define MAXLINE 1000
You can read more here http://gcc.gnu.org/onlinedocs/cpp/Object_002dlike-Macros.html#Object_002dlike-Macros
Upvotes: 3
Reputation: 25001
The #define
statement doesn't need the equals sign.
It should read:
#define MAXLINE 1000
Upvotes: 3