number of semicolons

Discussion in 'C Programming' started by Pietro Cerutti, Jan 24, 2008.

  1. 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
     
    Pietro Cerutti, Jan 24, 2008
    #1
    1. Advertising

  2. "Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
    news:ecb38$47987c11$50dabfec$...
    > 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
     
    Malcolm McLean, Jan 24, 2008
    #2
    1. Advertising

  3. Malcolm McLean wrote:
    >
    > "Pietro Cerutti" <gahr_AT_gahr_DOT_ch_DO_NOT_SPAM> wrote in message
    > news:ecb38$47987c11$50dabfec$...
    >> 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
     
    Pietro Cerutti, Jan 24, 2008
    #3
  4. Pietro Cerutti

    Guest

    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$...
    > >> 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
     
    , Jan 24, 2008
    #4
  5. 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$...
    >>>> 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
     
    Pietro Cerutti, Jan 24, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Mayer [C# MVP]
    Replies:
    2
    Views:
    2,959
    Andrew Baker
    Apr 15, 2004
  2. thehuby

    Semicolons inside a String

    thehuby, Aug 9, 2005, in forum: Java
    Replies:
    3
    Views:
    925
    Roedy Green
    Aug 10, 2005
  3. Jeremy Yallop

    Without semicolons

    Jeremy Yallop, May 10, 2004, in forum: C Programming
    Replies:
    27
    Views:
    1,095
    Dan Pop
    May 13, 2004
  4. Mage

    semicolons

    Mage, Apr 11, 2005, in forum: Python
    Replies:
    1
    Views:
    377
    Jeremy Bowers
    Apr 12, 2005
  5. Dave Brueck

    Re: semicolons

    Dave Brueck, Apr 11, 2005, in forum: Python
    Replies:
    0
    Views:
    356
    Dave Brueck
    Apr 11, 2005
Loading...

Share This Page