Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected , or ; before if

Tags:

c

gcc

I made a stupid mistake (forgot semicolon, too much Python lately), but got an interesting error message from gcc: "expected ',' or ';' before 'if'".

I know those error messages provide just an "upper bound" for possible source code, but I'd like to know if there is any construct in C such that "if" token really comes after ',' and not after ';'.

like image 902
Veky Avatar asked Dec 04 '12 11:12

Veky


People also ask

How to fix expected')'before';'token?

To fix this error, check the statement which should not be terminated and remove semicolons. To fix this error in this program, remove semicolon after the #define statement.

What does error')'expected mean?

It means the syntax is invalid.

How do you fix expected before else?

Error: Expected '}' before 'else' occurs, if closing scope curly brace of if statement is missing. How to fix? See the code, closing curly brace } is missing before else statement. To fix this error - close the if statement's scope properly.

What is mean by error expected before token?

It literally means what it's saying. You're missing an important parenthesis there, bud. Check your code before you hit the semicolon.


2 Answers

After isn't necessarily immediately after. The error message is more: 'I've just hit an 'if' construct. At this point I was expecting either an end to the (previous) statement, or the next item in the list. One of those things must be before this 'if', so I'm letting you know'

like image 198
mcalex Avatar answered Oct 16 '22 14:10

mcalex


I'd like to know if there is any construct in C such that "if" token really comes after ',' and not after ';'.

According to the C BNF grammar, an if is always at the beginning of a statement. So no, it can't be preceded by a ,.

like image 39
user703016 Avatar answered Oct 16 '22 13:10

user703016