Why doesn't GCC like it?
I am trying to learn C and find myself very stuck, no complaints :)
Anyway, I wrote a program and GCC doesn't like it. The following code is NOT a program, but it demonstrates 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 you replace the symbolic constant MAXLINE with int 1000, everything works.
What's happening?
When the preprocessor replaces your definition MAXLINE
, your code changes to
int main()
{
int tmp = = 1000;
char line[= 1000];
return 0;
}
The C preprocessor is very dumb! Don't add anything extra to #defines (no equals, no semicolons, nothing)
Definitions don't need equal signs :)
#define maxline 1000
Shouldn't be = just in the definition
#define MAXLINE 1000
The operator #define
does not need an equal sign.
He should read:
#define MAXLINE 1000
Use #define without '=':
#define MAXLINE 1000
You have
#define MAXLINE 1000
You can read more here http://gcc.gnu.org/onlinedocs/cpp/Object_002dlike-Macros.html#Object_002dlike-Macros
#define MAXLINE 1000