C/C++

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Reason for ISO ; warning

    22 answers - 255 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    [Warning] IS C does not allow extra ';' outside of a function
    int n;;
    int main(void)
    {
    }
    Anyone care to enlighten me as to why IS C does not allow this, but
    apparently ANSI c99 does?
    Ta
  • No.1 | | 452 bytes | |

    pemo wrote:

    [Warning] IS C does not allow extra ';' outside of a function

    int n;;

    That's an object definition,
    followed by what looks like an empty statement.

    int main(void)
    {

    }

    Anyone care to enlighten me as to why IS C does not allow this,

    Statements are only allowed inside of function definitions.

    but apparently ANSI c99 does?

    I don't know so much about C99.
  • No.2 | | 547 bytes | |

    pemo said:

    [Warning] IS C does not allow extra ';' outside of a function

    int n;;

    int main(void)
    {

    }

    Anyone care to enlighten me as to why IS C does not allow this,

    It's the grammar. I presume you mean C90, because

    but apparently ANSI c99 does?

    here you mean IS C99. ANSI didn't ratify the revised Standard until
    2000, so it's ANSI C2000 or, if you prefer, ANSI C00.

    I wasn't aware that executable code was allowed outside a function in C99.
    C&V?
  • No.3 | | 183 bytes | |

    Richard Heathfield wrote:
    I wasn't aware that executable code was
    allowed outside a function in C99.
    C&V?
    External definitions of objects are executable code.
  • No.4 | | 754 bytes | |


    "pete" <pfiland@mindspring.comwrote in message
    news:4396FBAE.931@mindspring.com
    pemo wrote:
    >>

    >[Warning] IS C does not allow extra ';' outside of a function
    >>

    >int n;;
    >

    That's an object definition,
    followed by what looks like an empty statement.
    >
    >>

    >int main(void)
    >{
    >
    >}
    >>

    >Anyone care to enlighten me as to why IS C does not allow this,
    >

    Statements are only allowed inside of function definitions.

    Yes, that makes sense - ta.

  • No.5 | | 1121 bytes | |


    "Richard Heathfield" <invalid@invalid.invalidwrote in message
    news:dn6u49$437$1@
    pemo said:
    >
    >[Warning] IS C does not allow extra ';' outside of a function
    >>

    >int n;;
    >>

    >int main(void)
    >{
    >
    >}
    >>

    >Anyone care to enlighten me as to why IS C does not allow this,
    >

    It's the grammar. I presume you mean C90, because
    >
    >but apparently ANSI c99 does?
    >

    here you mean IS C99. ANSI didn't ratify the revised Standard until
    2000, so it's ANSI C2000 or, if you prefer, ANSI C00.

    I wasn't aware that executable code was allowed outside a function in C99.
    C&V?

    Interesting!

    It's the grammar. I presume you mean C90

    'I' didn't come into it Richard, the message came from gcc and appears
    with -Wall -pedantic -std=c99

    So, I assume c99 is what you're caling c00?

  • No.6 | | 881 bytes | |

    pemo wrote:
    "Richard Heathfield" <invalid@invalid.invalidwrote in message
    news:dn6u49$437$1@
    >
    >>pemo said:
    >>


    >>

    but apparently ANSI c99 does?
    ^^^^
    This bit

    >>
    >>here you mean IS C99. ANSI didn't ratify the revised Standard until
    >>2000, so it's ANSI C2000 or, if you prefer, ANSI C00.
    >>


    <snip>

    --
    'I' didn't come into it Richard, the message came from gcc and appears
    with -Wall -pedantic -std=c99

    So, I assume c99 is what you're caling c00?
    --

    That gcc option means IS C99, there is no ANSI C99, which seems to be
    what R Heathfield was getting at.
  • No.7 | | 1046 bytes | |


    "Ian Malone" <ibm21@cam.ac.ukwrote in message
    news:439703FC.7010305@cam.ac.uk
    pemo wrote:
    >"Richard Heathfield" <invalid@invalid.invalidwrote in message
    >news:dn6u49$437$1@
    >>

    pemo said:

    but apparently ANSI c99 does?
    ^^^^
    This bit

    here you mean IS C99. ANSI didn't ratify the revised Standard until
    2000, so it's ANSI C2000 or, if you prefer, ANSI C00.

    <snip>
    >
    >>
    >>

    >'I' didn't come into it Richard, the message came from gcc and appears
    >with -Wall -pedantic -std=c99
    >>

    >So, I assume c99 is what you're caling c00?
    >>
    >>

    >

    That gcc option means IS C99, there is no ANSI C99, which seems to be
    what R Heathfield was getting at.

    Ah, ok, so is -ansi the ANSI variant then?

  • No.8 | | 858 bytes | |

    pemo said:

    the message came from gcc and appears
    with -Wall -pedantic -std=c99

    Despite the flag name, gcc does not fully support C99.

    So, I assume c99 is what you're caling c00?

    If you mean the IS C Standard, it's C99. If you mean the ANSI C Standard,
    it's C00.

    1989: ANSI C (C89).
    1990: IS C (C90) - this is effectively identical to C89, the only changes I
    know about being section number changes.
    1995: There was a minor mod to the Standard which, I believe, was adopted by
    both IS and ANSI.
    1999: IS C (C99).
    2000: ANSI C (C00 or C2000) - this is effectively identical to C99.

    Most people use C89 when they mean either C89 or C90, and C99 when they mean
    either C99 or C00/C2000 - despite the fact that C89 refers to the ANSI
    Standard and C99 refers to the IS Standard.
  • No.9 | | 498 bytes | |

    In article <dn6tcf$3pi$2@news.ox.ac.uk>, pemo <usenetmeister@gmail.comwrote:
    >Anyone care to enlighten me as to why IS C does not allow this, but
    >apparently ANSI c99 does?


    Ignoring the question of what ANSI c99 is, what makes you think that it
    allows it?

    When GCC says that IS C does not allow something, it probably means
    that GCC allows it as an extension, not that some ANSI C version
    allows it.
    -- Richard
  • No.10 | | 532 bytes | |

    In article <dn70b4$4s3$1@news.ox.ac.uk>, pemo <usenetmeister@gmail.comwrote:
    >Ah, ok, so is -ansi the ANSI variant then?


    There isn't an "ANSI variant". ANSI standardised C in 1989. IS
    adopted that definition in 1990. IS produced another standard in
    1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
    as IS C, and the versions can be referred to as C89 and C00 or C90
    and C99 depending on which standards body you prefer.
    -- Richard
  • No.11 | | 522 bytes | |

    Ian Malone said:

    That gcc option means IS C99, there is no ANSI C99, which seems to be
    what R Heathfield was getting at.

    Sorry I wasn't clear. I was actually trying to get two points across at the
    same time, always a bad idea.

    The first point was that the C99 switch in gcc is a bit optimistic. gcc does
    not fully support the new Standard, no matter what you choose to call it.

    The second point was about what you choose to call it!, and that has now
    been explained ad nauseam.
  • No.12 | | 1569 bytes | |


    "Richard Tobin" <richard@cogsci.ed.ac.ukwrote in message
    news:dn70rj$s8m$2@pc-news.cogsci.ed.ac.uk
    In article <dn70b4$4s3$1@news.ox.ac.uk>, pemo <usenetmeister@gmail.com>
    wrote:
    >>Ah, ok, so is -ansi the ANSI variant then?

    >

    There isn't an "ANSI variant". ANSI standardised C in 1989. IS
    adopted that definition in 1990. IS produced another standard in
    1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
    as IS C, and the versions can be referred to as C89 and C00 or C90
    and C99 depending on which standards body you prefer.

    Sorry, not what I meant as a question [my fault], it was more what -ansi
    *means* as a gcc switch.

    T here of course, but for completeness - here's what the manual says

    The original ANSI C standard (X3.159-1989) was ratified in 1989 and
    published in 1990.
    This standard was ratified as an IS standard (IS/IEC 9899:1990) later in
    1990. There
    were no technical differences between these publications, although the
    sections of the ANSI
    standard were renumbered and became clauses in the IS standard. This
    standard, in
    both its forms, is commonly known as C89, or occasionally as C90, from the
    dates of
    ratification. The ANSI standard, but not the IS standard, also came with a
    Rationale
    document. To select this standard in GCC, use one of the options '-ansi',
    '-std=c89' or
    '-std=iso9899:1990';

  • No.13 | | 1796 bytes | |

    2005-12-07 11:22:27 -0500, "pemo" <usenetmeister@gmail.comsaid:

    "Richard Tobin" <richard@cogsci.ed.ac.ukwrote in message
    news:dn70rj$s8m$2@pc-news.cogsci.ed.ac.uk
    >In article <dn70b4$4s3$1@news.ox.ac.uk>, pemo <usenetmeister@gmail.comwrote:

    Ah, ok, so is -ansi the ANSI variant then?
    >>

    >There isn't an "ANSI variant". ANSI standardised C in 1989. IS
    >adopted that definition in 1990. IS produced another standard in
    >1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
    >as IS C, and the versions can be referred to as C89 and C00 or C90
    >and C99 depending on which standards body you prefer.
    >

    Sorry, not what I meant as a question [my fault], it was more what
    -ansi *means* as a gcc switch.

    T here of course, but for completeness - here's what the manual says

    The original ANSI C standard (X3.159-1989) was ratified in 1989 and
    published in 1990.
    This standard was ratified as an IS standard (IS/IEC 9899:1990) later
    in 1990. There
    were no technical differences between these publications, although the
    sections of the ANSI
    standard were renumbered and became clauses in the IS standard. This
    standard, in
    both its forms, is commonly known as C89, or occasionally as C90, from
    the dates of
    ratification. The ANSI standard, but not the IS standard, also came
    with a Rationale
    document. To select this standard in GCC, use one of the options
    '-ansi', '-std=c89' or
    '-std=iso9899:1990';

    Well, the manual just told you; '-ansi' means the same as '-std=c89' or
    '-std=iso9899:1990'
  • No.14 | | 2137 bytes | |


    "Clark S. Cox III" <clarkcox3@gmail.comwrote in message
    @gmailcom
    2005-12-07 11:22:27 -0500, "pemo" <usenetmeister@gmail.comsaid:
    >
    >>

    >"Richard Tobin" <richard@cogsci.ed.ac.ukwrote in message
    >news:dn70rj$s8m$2@pc-news.cogsci.ed.ac.uk

    In article <dn70b4$4s3$1@news.ox.ac.uk>, pemo <usenetmeister@gmail.com>
    wrote:
    Ah, ok, so is -ansi the ANSI variant then?

    There isn't an "ANSI variant". ANSI standardised C in 1989. IS
    adopted that definition in 1990. IS produced another standard in
    1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
    as IS C, and the versions can be referred to as C89 and C00 or C90
    and C99 depending on which standards body you prefer.
    >>

    >Sorry, not what I meant as a question [my fault], it was more what -ansi
    >*means* as a gcc switch.
    >>

    >T here of course, but for completeness - here's what the manual says
    >>

    >The original ANSI C standard (X3.159-1989) was ratified in 1989 and
    >published in 1990.
    >This standard was ratified as an IS standard (IS/IEC 9899:1990) later
    >in 1990. There
    >were no technical differences between these publications, although the
    >sections of the ANSI
    >standard were renumbered and became clauses in the IS standard. This
    >standard, in
    >both its forms, is commonly known as C89, or occasionally as C90, from
    >the dates of
    >ratification. The ANSI standard, but not the IS standard, also came with
    >a Rationale
    >document. To select this standard in GCC, use one of the options '-ansi',
    >'-std=c89' or
    >'-std=iso9899:1990';
    >

    Well, the manual just told you; '-ansi' means the same as '-std=c89' or
    '-std=iso9899:1990'

    Um, yeah, I noticed! But thanks for pointing it out.

  • No.15 | | 1547 bytes | |

    "pemo" <usenetmeister@gmail.comwrites:
    [Warning] IS C does not allow extra ';' outside of a function

    int n;;

    int main(void)
    {

    }

    Anyone care to enlighten me as to why IS C does not allow this, but
    apparently ANSI c99 does?

    If "int n;;" appeared inside a function, it would be a declaration
    "int n;" followed by an empty statement ";". Since the grammar
    doesn't allow statements outside functions, "int n;;" outside a
    function is an error.

    As far as I know, this didn't change between C90 and C99; gcc seems to
    agree:

    % cat tmp.c
    int x;;
    % gcc | head -1
    gcc (GCC) 4.0.2
    % gcc -c -pedantic -std=c89 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=iso9899:1990 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=iso9899:199409 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=c99 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=c9x tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=iso9899:1999 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
    % gcc -c -pedantic -std=iso9899:1999 tmp.c
    tmp.c:1: warning: IS C does not allow extra ';' outside of a function
  • No.16 | | 2050 bytes | |

    Wed, 7 Dec 2005 15:48:53 +0000 (UTC), Richard Heathfield
    <invalid@invalid.invalidwrote in comp.lang.c:

    pemo said:

    the message came from gcc and appears
    with -Wall -pedantic -std=c99

    Despite the flag name, gcc does not fully support C99.

    So, I assume c99 is what you're caling c00?

    If you mean the IS C Standard, it's C99. If you mean the ANSI C Standard,
    it's C00.

    1989: ANSI C (C89).
    1990: IS C (C90) - this is effectively identical to C89, the only changes I
    know about being section number changes.
    1995: There was a minor mod to the Standard which, I believe, was adopted by
    both IS and ANSI.
    1999: IS C (C99).
    2000: ANSI C (C00 or C2000) - this is effectively identical to C99.

    Most people use C89 when they mean either C89 or C90, and C99 when they mean
    either C99 or C00/C2000 - despite the fact that C89 refers to the ANSI
    Standard and C99 refers to the IS Standard.

    Sheesh, you are not only beating a dead horse, you are beating it
    incorrectly. The ANSI delegation to IS voted to ratify the 1999
    version of the C standard at the same time that all other the member
    national standard bodies, except for the British who voted against it,
    did.

    Due to a procedural issue, meaning somebody at ANSI objected,
    ratification as an American National Standard required sending it out
    to their members as a vote. It was officially approved as an American
    National Standard on May 15, 2000.

    Nevertheless, if you point your favorite browser to:

    %2FIS%2FIEC+9899%2D1999

    you will see that for the princely sum of $18.00USD, you can still
    purchase:

    Document#: INCITS/IS/IEC 9899-1999
    Title: Programming Languages - C (formerly ANSI/IS/IEC
    9899-1999)

    The delay in ANSI approval as an American National Standard did not in
    any way change the date. ANSI C99 is "ANSI C99", not "ANSI C00" or
    "ANSI C2000". In fact, ANSI doesn't even call it an "ANSI" standard
    anymore.
  • No.17 | | 758 bytes | |

    Jack Klein said:

    Wed, 7 Dec 2005 15:48:53 +0000 (UTC), Richard Heathfield
    <invalid@invalid.invalidwrote in comp.lang.c:
    >
    >Most people use C89 when they mean either C89 or C90, and C99 when they
    >mean either C99 or C00/C2000 - despite the fact that C89 refers to the
    >ANSI Standard and C99 refers to the IS Standard.
    >

    Sheesh, you are not only beating a dead horse,

    It's what we do here. :-)

    you are beating it incorrectly.

    That's more serious. Since you know far more about this than I do, I'm happy
    to accept the correction and apologise for supplying misinformation.

    Just out of curiosity, what's the right way to beat a dead horse?
  • No.18 | | 620 bytes | |

    Richard Heathfield wrote:

    <snip>
    I wasn't aware that executable code was allowed outside a function in C99.
    C&V?

    not the standart, but the C99 Rationale:

    <quote>
    5.1.2 Execution Environments

    The definition of program startup in the Standard is designed to permit
    initialization of static
    storage by executable code, as well as by data translated into the program image.
    </quote>

    so this should be valid (and compiles with -Wall -pedantic -std=c99):

    #include <string.h>

    size_t blah = strlen("abc");

    /**/
  • No.19 | | 334 bytes | |

    Wolfgang Riedel wrote:
    so this should be valid (and compiles with -Wall -pedantic -std=c99):

    #include <string.h>

    size_t blah = strlen("abc");

    /**/

    It's not valid, and gcc produces the diagnostic message "initializer
    element is not constant" when compiled with exactly the options you give.
  • No.20 | | 1171 bytes | |

    Simon Biber wrote:

    Wolfgang Riedel wrote:
    so this should be valid
    (and compiles with -Wall -pedantic -std=c99):

    #include <string.h>

    size_t blah = strlen("abc");

    /**/

    It's not valid, and gcc produces the diagnostic message "initializer
    element is not constant"
    when compiled with exactly the options you give.

    C99
    6.7.8 Initialization

    [#4] All the expressions in an initializer for an object
    that has static storage duration shall be constant
    expressions or string literals.

    6.6 Constant expressions

    [#7] More latitude is permitted for constant expressions in
    initializers. Such a constant expression shall be, or
    evaluate to, one of the following:
    -- an arithmetic constant expression,
    -- a null pointer constant,
    -- an address constant, or
    -- an address constant for an object type plus or minus an
    integer constant expression.

    [#8] An arithmetic constant expression shall have arithmetic
    type and shall only have operands that are integer
    constants, floating constants, enumeration constants,
    character constants, and sizeof expressions.
  • No.21 | | 360 bytes | |

    Simon Biber wrote:

    Wolfgang Riedel wrote:
    so this should be valid (and compiles with -Wall -pedantic -std=c99):

    #include <string.h>

    size_t blah = strlen("abc");

    /**/

    It's not valid, and gcc produces the diagnostic message "initializer
    element is not constant" when compiled with exactly the options you give.
  • No.22 | | 2234 bytes | |

    Wolfgang Riedel wrote:
    Simon Biber wrote:
    >Wolfgang Riedel wrote:

    so this should be valid (and compiles with -Wall -pedantic -std=c99):

    #include <string.h>

    size_t blah = strlen("abc");

    /**/
    >It's not valid, and gcc produces the diagnostic message "initializer
    >element is not constant" when compiled with exactly the options you give.
    >>

    >--
    >Simon.
    >

    You snipped the rationale, I quoted.
    I think it's correct (evaluates to arithmetic constant exrpssion).

    No. The relevant definition is

    "An arithmetic constant expression shall have arithmetic type and shall only
    have operands that are integer constants, floating constants, enumeration
    constants, character constants, and sizeof expressions. Cast operators in an
    arithmetic constant expression shall only convert arithmetic types to
    arithmetic types, except as part of an operand to a sizeof operator whose
    result is an integer constant."

    'strlen("abc")' doesn't qualify. gcc is free to evaluate 'strlen("abc")' as
    a constant expression, but this does not make it an arithmetic constant
    expression. course, the initializer to "blah" need only be a constant
    expression. It doesn't have to be an arithmetic constant expression
    specifically.

    Btw. my gcc doesn't warn (maybe not the latest & greatest):

    <snip>
    Not a bug. Later versions of gcc do warn because standards-conforming
    compilers are not required to accept the program, but gcc does not violate
    the standard by not issuing a diagnostic -- implementations are expressly
    allowed to accept other forms of expressions as constant than the ones
    described by the standard.

    If you expect 'strlen("abc")' to be a constant expression, you're relying on
    an extension. It's not portable code.

    Note that gcc does *not* allow expressions that cannot be evaluated at
    compile time as initializers, and rightly so. This will not compile:

    size_t foo();
    size_t blah = foo();

    S.

Re: Reason for ISO ; warning


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "C/C++"

EMSDN.COM