Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

About the definition of __STDC_VERSION__ macro

948 views
Skip to first unread message

Karthik Kumar

unread,
Nov 3, 2004, 8:47:37 PM11/3/04
to
Hi,
I came to know about the macro thanks to this recent discussion in
c.l.c. and gnu.gcc.help - http://tinyurl.com/5ubqz .

I wrote this small program to get the version in GNU C/C++
implementation.

D:\>type std_info.c
#include <stdio.h>
#include <stdlib.h>

int main() {
int a = __STDC_VERSION__ ;
return EXIT_SUCCESS;
}

Apparently the macro was not defined. Can anyone tell me what I am
missing here ?

D:\>gcc std_info.c
std_info.c: In function `main':
std_info.c:5: error: `__STDC_VERSION__' undeclared (first use in this
function)
std_info.c:5: error: (Each undeclared identifier is reported only once
std_info.c:5: error: for each function it appears in.)

BTW - I run GNU C/C++ on Windows. The version is here.

D:\>gcc --version
gcc (GCC) 3.4.2 (mingw-special)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '

Larry I Smith

unread,
Nov 3, 2004, 11:04:49 PM11/3/04
to

Try:

gcc -std=c99 -o std_info std_info.c

--
Anti-spam address, change each 'X' to '.' to reply directly.

Karthik Kumar

unread,
Nov 4, 2004, 1:43:34 AM11/4/04
to
Larry I Smith wrote:
> Karthik Kumar wrote:
>
>> Hi,
>> I came to know about the macro thanks to this recent discussion in
>> c.l.c. and gnu.gcc.help - http://tinyurl.com/5ubqz .
>>
>> I wrote this small program to get the version in GNU C/C++
>> implementation.
>>
>> D:\>type std_info.c
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main() {
>> int a = __STDC_VERSION__ ;
>> return EXIT_SUCCESS;
>> }
>>
[ info. skipped]

>>
>
> Try:
>
> gcc -std=c99 -o std_info std_info.c
>

Thanks a lot for that. Specifying c99 explicitly
defines the macro.

Michael Mair

unread,
Nov 4, 2004, 2:22:58 AM11/4/04
to
Karthik Kumar wrote:

> Larry I Smith wrote:
>
>> Karthik Kumar wrote:
>>
>>> Hi,
>>> I came to know about the macro thanks to this recent discussion in
>>> c.l.c. and gnu.gcc.help - http://tinyurl.com/5ubqz .
>>>
>>> I wrote this small program to get the version in GNU C/C++
>>> implementation.
>>>
>>> D:\>type std_info.c
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> int main() {
>>> int a = __STDC_VERSION__ ;
>>> return EXIT_SUCCESS;
>>> }
>>>
> [ info. skipped]
>
>>>
>>
>> Try:
>>
>> gcc -std=c99 -o std_info std_info.c
>>
> Thanks a lot for that. Specifying c99 explicitly
> defines the macro.

Yup, it is better to use __STDC_VERSION__ in preprocessor
directives (with #ifdef or #if __STDC_VERSION__ >= ...)

As C99 still is not completely supported (the only compiler/
library combination that claims this is Comeau C+Dinkumware
standard library) by gcc, the default standard is gnu89, that
is, c89 + GNU extensions. As soon as C99 (and hence the standard
c99) is available, the default standard will be gnu99.
If you want to write "pure" C, you should use -pedantic in
conjunction with -std=c99 (or -std=c89/-ansi); this makes sure
that no non-standard stuff is allowed.


Cheers
Michael

--
E-Mail: Mine is an /at/ gmx /dot/ de address.

Karthik Kumar

unread,
Nov 4, 2004, 2:39:36 AM11/4/04
to
Michael Mair wrote:
> Karthik Kumar wrote:
>
>> Larry I Smith wrote:
>>
>>> Karthik Kumar wrote:
>>>
>>>> Hi,
>>>> I came to know about the macro thanks to this recent discussion in
>>>> c.l.c. and gnu.gcc.help - http://tinyurl.com/5ubqz .
>>>>
>>>> I wrote this small program to get the version in GNU C/C++
>>>> implementation.
>>>>
>>>> D:\>type std_info.c
>>>> #include <stdio.h>
>>>> #include <stdlib.h>
>>>>
>>>> int main() {
>>>> int a = __STDC_VERSION__ ;
>>>> return EXIT_SUCCESS;
>>>> }
>>>>
>> [ info. skipped]
>>
>>>>
>>>
>>> Try:
>>>
>>> gcc -std=c99 -o std_info std_info.c
>>>
>> Thanks a lot for that. Specifying c99 explicitly
>> defines the macro.
>
>
> Yup, it is better to use __STDC_VERSION__ in preprocessor
> directives (with #ifdef or #if __STDC_VERSION__ >= ...)

Yeah.. I know. In fact , thatz what my real program does.
I had posted a minimal fragment to focus on the macro better.

>
> As C99 still is not completely supported (the only compiler/
> library combination that claims this is Comeau C+Dinkumware
> standard library) by gcc, the default standard is gnu89, that
> is, c89 + GNU extensions. As soon as C99 (and hence the standard
> c99) is available, the default standard will be gnu99.

What do you mean here ? I thought c99 is already available.
In fact I got this macro only after reading the c99 manual.
Also when you say c99 is not completely supported, can you
point me to some kind a documentation on the current status
of the support of c99 on gcc system.

> If you want to write "pure" C, you should use -pedantic in
> conjunction with -std=c99 (or -std=c89/-ansi); this makes sure
> that no non-standard stuff is allowed.
>

--

Michael Mair

unread,
Nov 4, 2004, 3:18:38 AM11/4/04
to
>> As C99 still is not completely supported (the only compiler/
>> library combination that claims this is Comeau C+Dinkumware
>> standard library) by gcc, the default standard is gnu89, that
>> is, c89 + GNU extensions. As soon as C99 (and hence the standard
>> c99) is available, the default standard will be gnu99.
>
>
> What do you mean here ? I thought c99 is already available.
> In fact I got this macro only after reading the c99 manual.
> Also when you say c99 is not completely supported, can you
> point me to some kind a documentation on the current status
> of the support of c99 on gcc system.

Many features, especially the library, are mostly available
but there are some things that will break the way GNU extensions
worked up to now (VLAs, flexible array members, inline keyword, ...)
Information is available from
http://gcc.gnu.org/c99status.html

Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Guy Harrison

unread,
Nov 4, 2004, 5:00:08 AM11/4/04
to
Karthik Kumar wrote:

> Hi,
> I came to know about the macro thanks to this recent discussion in
> c.l.c. and gnu.gcc.help - http://tinyurl.com/5ubqz .
>
> I wrote this small program to get the version in GNU C/C++
> implementation.
>
> D:\>type std_info.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int main() {
> int a = __STDC_VERSION__ ;
> return EXIT_SUCCESS;
> }
>
> Apparently the macro was not defined. Can anyone tell me what I am
> missing here ?

Option "-std=c99"

//#ifdef / #if defined __STDC_VERSION__

> D:\>gcc std_info.c
> std_info.c: In function `main':
> std_info.c:5: error: `__STDC_VERSION__' undeclared (first use in this
> function)
> std_info.c:5: error: (Each undeclared identifier is reported only once
> std_info.c:5: error: for each function it appears in.)
>
> BTW - I run GNU C/C++ on Windows. The version is here.
>
> D:\>gcc --version
> gcc (GCC) 3.4.2 (mingw-special)

TBH, either your code uses features such as Variable Length Arrays or it
doesn't - ie: your code will either compile with any C compiler or only
with C99 compliant one (not C++ btw) so you may as well say...

#ifndef __STDC_VERSION
# error blah
#endif

...in a global application header.

Unfortunately, C99 compliance isn't complete (Re: Michael's post - Comeau)
so for meantime you'll likely end up up wandering through target specific
macros (__MINGW32__ , __CYGWIN__ , __BORLANDC__ etc). :-(


0 new messages