number of semicolons

P

Pietro Cerutti

Hi group,

is the below valid?

int main(void)
{
int i = 4;;;;;;;;
}

It compiles cleanly with GCC -Wall.

I don't see any reason for that, any clarification is welcome!

Thanks,
 
M

Malcolm McLean

Pietro Cerutti said:
Hi group,

is the below valid?

int main(void)
{
int i = 4;;;;;;;;
}

It compiles cleanly with GCC -Wall.

I don't see any reason for that, any clarification is welcome!
The null statement is allowed.

It means you can do things like

/* execute foo() until it return a zero */
while( foo() );

instead of having to write

while( foo() )
continue;

Obviously your example was pointless, but it would be harder to forbid it
than to allow it.
 
P

Pietro Cerutti

Malcolm said:
The null statement is allowed.

It means you can do things like

/* execute foo() until it return a zero */
while( foo() );

instead of having to write

while( foo() )
continue;

Obviously your example was pointless, but it would be harder to forbid
it than to allow it.

Obvious... my example (which comes from a typo I did) was so pointless
that I didn't see it as a sequence of null operations...

Thanks and sorry for the noise...
 
F

fred.l.kleinschmidt

Obvious... my example (which comes from a typo I did) was so pointless
that I didn't see it as a sequence of null operations...

Thanks and sorry for the noise...

--
Pietro Cerutti

PGP Public Key:http://gahr.ch/pgp- Hide quoted text -

- Show quoted text -

But be careful under C89:
This compiles fine with no complaints:

void foo() {
int i;
int j;;

i = 2;
/* more code here */
}

But then you decide to add another variable:

void foo() {
int i;
int j;;
int k;

i = 2;
/* more code here */
}

Now the compiler complains, and you have a hard time trying to
figure out why adding "int k;" could cause a problem.
 
P

Pietro Cerutti

But be careful under C89:
This compiles fine with no complaints:

void foo() {
int i;
int j;;

i = 2;
/* more code here */
}

But then you decide to add another variable:

void foo() {
int i;
int j;;
int k;

i = 2;
/* more code here */
}

Now the compiler complains, and you have a hard time trying to
figure out why adding "int k;" could cause a problem.

Very sharp point. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top