#define for C99?

T

Tom St Denis

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
 
A

Arthur J. O'Dwyer

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
 
P

Peter Nilsson

Arthur said:
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.
 
T

Tom St Denis

Peter said:
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
 
J

J. J. Farrell

Tom said:
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?
 
T

Tom St Denis

Tom said:
Peter said:
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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top