473,320 Members | 1,933 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,320 software developers and data experts.

#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

Nov 21 '06 #1
5 5252

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
Nov 21 '06 #2
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

Nov 21 '06 #3
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

Nov 21 '06 #4

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?

Nov 21 '06 #5

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

Nov 26 '06 #6

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

Similar topics

18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
2
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made,...
3
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
by: pozz | last post by:
Hi all, I have the below #defines #define NUMBER1 30 #define NUMBER2 50 #define SUM (NUMBER1+NUMBER2) #define STRING1 "Byte: \x30" #define STRING2 "Byte: \x50"...
34
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
17
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
2
by: badc0de | last post by:
Hello.. a header file of one of my project has macro definitions like this (for example) #define PART_A_SORT_1_LABEL_STRING1 100 #define PART_A_SORT_1_LABEL_STRING2 200 #define...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: 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)...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.