473,287 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

detecting standard support

Is there are standard way to detect which C standard is supported by the
compiler?
I mean for conditional compilation like:

#if defined(C99)
# include "stdint.h"
#endif
Jun 3 '06 #1
5 2816
copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?
You can use the __STDC_VERSION__ macro. For C99, it must be defined to
199901L.
I mean for conditional compilation like:

#if defined(C99)
#if __STDC_VERSION__ >= 199901L

Prior to C99, __STDC_VERSION__ was either undefined, or defined to
199409L. (Actually, it's possible that C89 implementations are allowed
to define __STDC_VERSION__ to whatever they want -- I'm not sure -- but
they would only do so if they are intentionally useless.)
# include "stdint.h"
I think you mean <stdint.h>. It's not the same thing.
#endif


Jun 3 '06 #2
copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?
I mean for conditional compilation like:

#if defined(C99)
# include "stdint.h"
#endif


The 1989 Standard defines the __STDC__ predefined macro, this must be 1
on a conforming implementation. Amendment 1 to the 1989 Standard also
defines the predefined macro __STDC_VERSION__ which will be 199409L for
C89 Amendment 1 and 199901L for C99. You can use these two macros to
determine what version your implementation purportedly conforms to:

#include <stdio.h>

#if defined(__STDC__)
# if __STDC_VERSION__ >= 199901L
# define VERSION "C99 or greater"
# elif __STDC_VERSION__ >= 199409L
# define VERSION "C89 with Amendment 1"
# else
# define VERSION "C89"
# endif
#else
# define VERSION "Pre-C89"
#endif

int main (void) {
puts(VERSION);
return 0;
}

$ gcc -Wall -W -ansi -pedantic print_standard_version.c -o
print_standard_version
$ ./print_standard_version
C89

$ gcc -Wall -W -std=iso9899:199409 -pedantic print_standard_version.c
-o \
print_standard_version
$ ./print_standard_version
C89 with Amendment 1

$ gcc -Wall -W -std=c99 -pedantic print_standard_version.c -o
print_standard_version
$ ./print_standard_version
C99 or greater

Robert Gamble

Jun 3 '06 #3
Harald van Dijk schrieb:
copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?
You can use the __STDC_VERSION__ macro. For C99, it must be defined to
199901L.
I mean for conditional compilation like:

#if defined(C99)


#if __STDC_VERSION__ >= 199901L


Thanks!
Prior to C99, __STDC_VERSION__ was either undefined, or defined to
199409L. (Actually, it's possible that C89 implementations are allowed
to define __STDC_VERSION__ to whatever they want -- I'm not sure -- but
they would only do so if they are intentionally useless.)
# include "stdint.h"


I think you mean <stdint.h>. It's not the same thing.


Yes, of course.
#endif


Jun 3 '06 #4
Robert Gamble schrieb:
copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?
I mean for conditional compilation like:

#if defined(C99)
# include "stdint.h"
#endif


The 1989 Standard defines the __STDC__ predefined macro, this must be 1
on a conforming implementation. Amendment 1 to the 1989 Standard also
defines the predefined macro __STDC_VERSION__ which will be 199409L for
C89 Amendment 1 and 199901L for C99. You can use these two macros to
determine what version your implementation purportedly conforms to:

[snip]

Thanks!
Jun 3 '06 #5
"Harald van Dijk" <tr*****@gmail.com> writes:
copx wrote:
Is there are standard way to detect which C standard is supported by the
compiler?


You can use the __STDC_VERSION__ macro. For C99, it must be defined to
199901L.
I mean for conditional compilation like:

#if defined(C99)


#if __STDC_VERSION__ >= 199901L

Prior to C99, __STDC_VERSION__ was either undefined, or defined to
199409L. (Actually, it's possible that C89 implementations are allowed
to define __STDC_VERSION__ to whatever they want -- I'm not sure -- but
they would only do so if they are intentionally useless.)


I was going to suggest that you should always test whether
__STDC_VERSION__ is defined before checking its value -- but then I
remembered that any undefined identifiers in a #if directive are
replaced with 0. So the test

#if __STDC_VERSION__ >= 199901L

will work properly whether __STDC_VERSION__ is defined or not.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom | last post by:
Hi, I would like to use the standard PHP sessions and I understand they rely on the target web browser to support session cookies. I have tried the following code: <? session_start(); if...
3
by: raptor | last post by:
hi, how to detect opera..it seems that even opera8 doesnt support xmlhttp fully (.i.e. sendRequestHeader). I ask this 'cause opera seems to mimic IE, at least in the preferences ?! I havent...
7
by: fox | last post by:
Maybe this is not the best group to ask this question, but I don't know a better one. I'm looking for a *portable* program in C (I mean source code) to detect whether unaligned word access is:...
0
by: June Li | last post by:
H I got a problem with detecting sound card with Windows xp I am working on an application to test microphone. First I need detect if there is a sound card installed (or integrated audio...
25
by: Matt Kruse | last post by:
According to HTTP/1.1 specs, a client should only have two connections open to the host at a time (which can be changed by browser users, of course). When using xmlHttpRequest connections, is...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
4
by: Diego Martins | last post by:
Hi all! I am doing a crude investigation of memory leaks in objects created by external libraries. Since I don't have access to the source code, I can't tell if an object are freeing its resources...
3
by: dbuchanan | last post by:
How, at rundime, do I capture the fact that the parametrized query that fills a CheckBoxList results in an empty set. When the dataset is empty the CheckBoxList does not appear. I would like to...
15
by: RobG | last post by:
When using createEvent, an eventType parameter must be provided as an argument. This can be one of those specified in DOM 2 or 3 Events, or it might be a proprietary eventType. My problem is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.