473,385 Members | 1,359 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,385 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 2823
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.