![]() |
#define for C99?
I'm adding UTF-8 support to my crypto lib and I want to avoid dying on
pre-C99 platforms. I plan to just typedef wchar_t to unsigned long for them. Is there a #define for C99 compliance I could ifdef around to see if it's available? e.g. #ifndef __C99__ typedef unsigned long wchar_t; #else #include <wchar.h> #endif Thanks, Tom |
Re: #define for C99?
On Mon, 20 Nov 2006, Tom St Denis wrote: > > I'm adding UTF-8 support to my crypto lib and I want to avoid dying on > pre-C99 platforms. I plan to just typedef wchar_t to unsigned long for > them. Is there a #define for C99 compliance I could ifdef around to > see if it's available? > e.g. > > #ifndef __C99__ You want #if __STDC_VERSION__ >= 199901L __STDC_VERSION__ was 199409L in C95, and undefined (thus macro-expanding to zero) in C90. I'm sure this is in a FAQ somewhere. It's certainly in the Standard (and drafts thereof). HTH, -Arthur |
Re: #define for C99?
Arthur J. O'Dwyer wrote:
> On Mon, 20 Nov 2006, Tom St Denis wrote: > > I'm adding UTF-8 support to my crypto lib and I want to avoid dying on > > pre-C99 platforms. I plan to just typedef wchar_t to unsigned long for > > them. Is there a #define for C99 compliance I could ifdef around to > > see if it's available? > > e.g. > > > > #ifndef __C99__ > > You want > #if __STDC_VERSION__ >= 199901L ITYM <= > __STDC_VERSION__ was 199409L in C95, and undefined (thus macro- > expanding to zero) in C90. C90 did not require an implementation to define it, but since it is a reserved identifier, there is nothing preventing a C90 implementation from defining whatever it wants for __STDC_VERSION__. One alternative is to check for SIZE_MAX in <limits.h>. A conforming C90 implementation cannot define that macro; a C99 implementation must. Since it sounds like the OP is really checking for whcar_t, the WCHAR_MAX would distinguish C94/95/99 implementations from C90 ones. -- Peter |
Re: #define for C99?
Peter Nilsson wrote:
> One alternative is to check for SIZE_MAX in <limits.h>. A conforming > C90 > implementation cannot define that macro; a C99 implementation must. > > Since it sounds like the OP is really checking for whcar_t, the > WCHAR_MAX > would distinguish C94/95/99 implementations from C90 ones. Thanks to both, testing for WCHAR_MAX is probably the simplest. For my purposes all I'm doing is encoding/decoding ASN.1 so all the string routines [e.g., wcstrcmp or whatever] don't matter to me. Ideally I'd like to use wchar_t for people with C99 platforms so they don't have to cast or convert to the proper type to use the C functions for wchar strings. Coolies. Thanks, Tom |
Re: #define for C99?
Tom St Denis wrote: > I'm adding UTF-8 support to my crypto lib and I want to avoid dying on > pre-C99 platforms. I plan to just typedef wchar_t to unsigned long for > them. Is there a #define for C99 compliance I could ifdef around to > see if it's available? > > e.g. > > #ifndef __C99__ > typedef unsigned long wchar_t; > #else > #include <wchar.h> > #endif But wchar_t is part of C89 and the more complete library support for wide characters appeared in C94. Why would testing for C99 be relevant? |
Re: #define for C99?
Tom St Denis wrote: > Peter Nilsson wrote: > > One alternative is to check for SIZE_MAX in <limits.h>. A conforming > > C90 > > implementation cannot define that macro; a C99 implementation must. > > > > Since it sounds like the OP is really checking for whcar_t, the > > WCHAR_MAX > > would distinguish C94/95/99 implementations from C90 ones. > > Thanks to both, testing for WCHAR_MAX is probably the simplest. For my > purposes all I'm doing is encoding/decoding ASN.1 so all the string > routines [e.g., wcstrcmp or whatever] don't matter to me. Ideally I'd > like to use wchar_t for people with C99 platforms so they don't have to > cast or convert to the proper type to use the C functions for wchar > strings. Just a follow up ... what I have so far ... :-( #if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED)) && !defined(LTC_NO_WCHAR) #include <wchar.h> #else typedef ulong32 wchar_t; #endif [excuse the wrapped lines...] It seems that gcc will not natively define __STDC_VERSION [or to match the restraint]. Also WCHAR_MAX is only defined if you explicitly include wchar.h ... (my guess is you need to force --std=c99 for that to show up...) _WCHAR_T is defined through some standard glibc headers and _WCHAR_T_DEFINED through some VC6 headers.... Tom |
| All times are GMT. The time now is 11:59 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.