Reason for ISO ; warning

P

pemo

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

int n;;

int main(void)
{
....
}

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

Ta
 
P

pete

pemo said:
[Warning] ISO 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 ISO 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.
 
R

Richard Heathfield

pemo said:
[Warning] ISO C does not allow extra ';' outside of a function

int n;;

int main(void)
{
...
}

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

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

....here you mean ISO 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?
 
P

pete

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

pemo

pete said:
pemo said:
[Warning] ISO 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 ISO C does not allow this,

Statements are only allowed inside of function definitions.

Yes, that makes sense - ta.
 
P

pemo

Richard Heathfield said:
pemo said:
[Warning] ISO C does not allow extra ';' outside of a function

int n;;

int main(void)
{
...
}

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

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

...here you mean ISO 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!

'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?
 
I

Ian Malone

^^^^
This bit

'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 ISO C99, there is no ANSI C99, which seems to be
what R Heathfield was getting at.
 
R

Richard Heathfield

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 ISO C Standard, it's C99. If you mean the ANSI C Standard,
it's C00.

1989: ANSI C (C89).
1990: ISO 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 ISO and ANSI.
1999: ISO 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 ISO Standard.
 
P

pemo

Ian Malone said:
^^^^
This bit




That gcc option means ISO 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?
 
R

Richard Tobin

Anyone care to enlighten me as to why ISO 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 ISO C does not allow something, it probably means
that GCC allows it as an extension, not that some ANSI C version
allows it.

-- Richard
 
R

Richard Tobin

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

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

-- Richard
 
R

Richard Heathfield

Ian Malone said:
That gcc option means ISO 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.
 
P

pemo

Richard Tobin said:
There isn't an "ANSI variant". ANSI standardised C in 1989. ISO
adopted that definition in 1990. ISO produced another standard in
1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
as ISO 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.

OT 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 ISO standard (ISO/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 ISO 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 ISO 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';
 
C

Clark S. Cox III

Richard Tobin said:
There isn't an "ANSI variant". ANSI standardised C in 1989. ISO
adopted that definition in 1990. ISO produced another standard in
1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
as ISO 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.

OT 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 ISO standard (ISO/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 ISO 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 ISO 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'
 
P

pemo

Clark S. Cox III said:
Richard Tobin said:
Ah, ok, so is -ansi the ANSI variant then?

There isn't an "ANSI variant". ANSI standardised C in 1989. ISO
adopted that definition in 1990. ISO produced another standard in
1999, which (apparently) ANSI adopted in 2000. So ANSI C is the same
as ISO 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.

OT 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 ISO standard (ISO/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 ISO 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 ISO 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.
 
K

Keith Thompson

pemo said:
[Warning] ISO C does not allow extra ';' outside of a function

int n;;

int main(void)
{
...
}

Anyone care to enlighten me as to why ISO 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 --version | head -1
gcc (GCC) 4.0.2
% gcc -c -pedantic -std=c89 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=iso9899:1990 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=iso9899:199409 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=c99 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=c9x tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=iso9899:1999 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
% gcc -c -pedantic -std=iso9899:1999 tmp.c
tmp.c:1: warning: ISO C does not allow extra ';' outside of a function
 
J

Jack Klein

pemo said:


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


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

1989: ANSI C (C89).
1990: ISO 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 ISO and ANSI.
1999: ISO 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 ISO Standard.

Sheesh, you are not only beating a dead horse, you are beating it
incorrectly. The ANSI delegation to ISO 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:

http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS/ISO/IEC+9899-1999

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

Document#: INCITS/ISO/IEC 9899-1999
Title: Programming Languages - C (formerly ANSI/ISO/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.
 
R

Richard Heathfield

Jack Klein said:
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?
 
W

Wolfgang Riedel

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");

/*...*/
 
S

Simon Biber

Wolfgang said:
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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top