Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > number of semicolons

Reply
Thread Tools

number of semicolons

 
 
Pietro Cerutti
Guest
Posts: n/a
 
      01-24-2008
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,

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      01-24-2008

"Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
news:ecb38$47987c11$50dabfec$(E-Mail Removed) ...
> 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.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

 
Reply With Quote
 
 
 
 
Pietro Cerutti
Guest
Posts: n/a
 
      01-24-2008
Malcolm McLean wrote:
>
> "Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
> news:ecb38$47987c11$50dabfec$(E-Mail Removed) ...
>> 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.
>


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
 
Reply With Quote
 
fred.l.kleinschmidt@boeing.com
Guest
Posts: n/a
 
      01-24-2008
On Jan 24, 4:00*am, Pietro Cerutti <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM>
wrote:
> Malcolm McLean wrote:
>
> > "Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
> >news:ecb38$47987c11$50dabfec$(E-Mail Removed) h...
> >> 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.

>
> 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.
--
Fred Kleinschmidt
 
Reply With Quote
 
Pietro Cerutti
Guest
Posts: n/a
 
      01-24-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Jan 24, 4:00 am, Pietro Cerutti <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM>
> wrote:
>> Malcolm McLean wrote:
>>
>>> "Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
>>> news:ecb38$47987c11$50dabfec$(E-Mail Removed) ...
>>>> 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.

>> 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.


Very sharp point. Thanks!

> --
> Fred Kleinschmidt



--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Semicolons inside a String thehuby Java 3 08-10-2005 02:43 AM
semicolons Mage Python 1 04-11-2005 11:32 PM
Re: semicolons Dave Brueck Python 0 04-11-2005 10:37 PM
Without semicolons Jeremy Yallop C Programming 27 05-13-2004 11:17 AM
Re: Why doesnt VB.Net allow semicolons at end of the statement? Michael Mayer [C# MVP] ASP .Net 2 04-15-2004 01:18 AM



Advertisments