I have this simple program:
#include
struct S
{
int i;
};
void swap(struct S *a, struct S *b)
{
struct S temp;
temp = *a /*
Why doesn't the compiler detect the missing semicolon?
There are three things to remember.
* in C can be both a unary and a binary operator. As a unary operator it means "dereference", as a binary operator it means "multiply".The result of these two facts is when we parse.
temp = *a /* Oops, missing a semicolon here... */
*a = *b;
The first and last * are interpreted as unary but the second * is interpreted as binary. From a syntax perspective, this looks OK.
It is only after parsing when the compiler tries to interpret the operators in the context of their operand types that an error is seen.