COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### #define for C99?

• Email
• Follow

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


 0
Reply tomstdenis (380) 11/21/2006 12:33:30 AM

See related articles to this posting

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

 0
Reply ajonospam (382) 11/21/2006 1:34:42 AM

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


 0
Reply airia (1802) 11/21/2006 2:07:35 AM

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


 0
Reply tomstdenis (380) 11/21/2006 2:17:40 AM

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?


 0
Reply jjf (517) 11/21/2006 4:22:41 AM

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

Tom


 0
Reply tomstdenis (380) 11/26/2006 12:58:02 PM

5 Replies
65 Views

Similar Articles

12/12/2013 5:27:52 AM
page loaded in 39968 ms. (0)

Similar Artilces:

Using parenthesis with defined (#if defined(...))
Is there any reason why I would ever want to use parenthesis with defined: #if defined(A_MACRO_NAME) Angel Tsankov wrote: > Is there any reason why I would ever want to use parenthesis with > defined: > #if defined(A_MACRO_NAME) I use parentheses if more than one macro needs to be tested: #if defined(A) && defined(B) It's not necessary, but it reads better. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask ...

Getting function not defined error after defining the function
Hi, I include this Javascript at the top of my page just below the <head> and <title> elements ... <script type="text/javascript"> function reloadIfUnavailable() { if (document.title.indexOf('Page Unavailable') > -1) { window.location.reload(); } else { setTimeout('reloadIfUnavilable()', 500); } // if } // reloadIfUnavailable setTimeout('reloadIfUnavailable()', 500); </script> However, get an error on Firefox (using 3.6 on Mac 10.6.3) ... reloadIfUnavilable is not defined setTimeo...

How defined is this?
Problem: I want to pass an Enum as an integer reference. Solution: void MyFunc ( int& MyInt ) { std::cout << "Value is:" << MyInt << std::endl; } enum Enumerator { ZERO = 0, ONE, TWO, THREE }; int main() { Enumerator MyEnum = ONE; if ( sizeof( MyEnum ) == sizeof( int ) ) MyFunc( *reinterpret_cast<int*>( &MyEnum ) ); } Is this guaranteed to work if sizeof( Enumerator ) == sizeof( int ) ? By work I mean is this program guaranteed to output 1 in all cases? Jim Langston wrote: > Problem: I want to pass an ...

Difference between "library parts" of C99 and "language parts" of C99
Hello! What is the difference between "library parts" of C99 and "language parts" of C99. see http://groups.google.at/group/microsoft.public.vc.language/browse_thread/thread/e9a67f0ff20a954b/bd2bada2bbdbce56?lnk=st&rnum=1#bd2bada2bbdbce56 I know that "Dinkum Compleat Libraries" (http://www.dinkumware.com/) support the "library parts" of C99 - this probably relates to the C99 library headers and the functionality they provide.? Are the "language parts" of C99 perhaps things like "variable declarations" in the middle of {}-bloc...

typedef and #define
What will happen if i replace a typedef with a #define? vivek wrote: > What will happen if i replace a typedef with a #define? See: <http://c-faq.com/decl/typedefvsdefine.html> vivek wrote: > What will happen if i replace a typedef with a #define? Your code will break [1]. [1] Probably. Why court disaster? Why replace the right construct with the wrong one? -- "Ashes are burning the way." - Renaissance, /Ashes Are Burning/ Hewlett-Packard Limited registered no: registered office: Cain Road, Bracknell...

Defining derivatives
(I am sorry if this or similar question was already answered. I did archive search, but didn't find anything.) I have a function: QuarticSpline[x_] := Module[ { r }, r = Abs[x]; If [r > 1.0, 0.0, 1 + r r (-6 + r (8 - 3 r)) ] ] It's first derivative should be (at least for my purposes :o) : QuarticSplineD1 [x_] := Module[ { r }, r = Abs [x]; If [r > 1.0, 0.0, Sign[x] * r (-12 + (24 r - 12)) ] ] but D[QuarticSpline[x], x] ret...

C99 parser ?
Can anyone point me to open-source software that performs the front- end parsing and analysis of C source? I am not interested in a full compiler, just something which checks syntax and semantics. I am intending to use it to examine what's involved in creating a parser, and to learn the syntax and semantics of the C99 standard. While I have the standard and am currently reading it, I would like some sort of software to look at to ensure I don't miss anything, if that makes sense... Regards, B. On Sep 25, 4:39 pm, boroph...@gmail.com wrote: > Can anyone point me to open-source ...

Defining a symbol
I need to define a symbol. The size of the symbol (the =93box=94 it is in) must be the same as the size of \top. It should consist of a small \top in the upper left corner and a small \times in the lower right corner, like this: T X I would appreciate it very much if someone could tell me how to do that. Best regards Casper Casper Storm Hansen <casper_storm_hansen@hotmail.com> wrote: > I need to define a symbol. The size of the symbol (the �box� it is in) > must be the same as the size of \top. It should consist of a small > \top in the upper left corner ...

some C99 feature
I'd like to draw your attention to a C99 feature that hasn't been implemented in lcc yet. Macro arguments can be empty in C99. #define P(x) x ## printf int main() { P(f)(stdout, "hello\n"); // should expand to fprintf, works P()("hello\n"); // should expand to printf, doesn't work return 0; } lcc says for the second P(): "Disagreement in number of macro arguments" ...

DEFINEs in Perl?
Hi all, I tried looking this up in perldoc and faq, but other than using the word DEFINE (where I know it from C)I don't know how else to describe it so can't find it. In Perl I am writing: sub_XYZ (value_a, value_b, 1); within sub_XYZ I have: if($third_value == 1) do this elsif($third_value == 2) do that elsif($third_value == 3) do the other thing Now for those not familiar with C, there is something called "#define", where I can declare: #define OptionA 1 #define OptionB 2 #define OptionC 3 and then in the... defining cmyk i want to know what softwares can defined the cmyk out off colors i mean that after scanning colors (image with some colors) the software will tell me how much percent in: c m y k thenks ... Define an Expression Hello to all, I would like to use the EQW to create an expression, use ENTER to place it on the stack, use INTVX or DERVX to manipulate it, and then somehow define it to the form << -> x 'new_expr' >> so it can be evaluated numerically. Quickly. Sometimes these expressions get quite involved, so I'm simply trying to avoid typing in the result of INTVX or DERVX into EQW; I would like to use the result of the INTVX or DERVX operation directly. I guess I need to find a way to prepend 'F(X)=' to the result of the INTVX or DERVX operation so I ... cannot be defined as a procedure here Is there a list of error messages of logo and what they mean? What does " cannot be defined as a procedure here " mean? Thanks "a11" <ashabsurya@gmail.com> writes: >Is there a list of error messages of logo and what they mean? They'll be somewhat different in different implementations of Logo. In particular, I've never seen >" cannot be defined as a procedure here " What version are you using? And what exactly did you say to get that message? ... Function is not defined (but it is) I declared a function in a file called somefile.js as follows: function foo() { alert ("yippi!"); } In HTML-file i'm importing it by adding: onClick=3D'foo()' The somefile.js is imported correctly (according to my breakpoints in = FireBug SOME code in the file is reached). Despite of that, as i cause t= he = onClick-event to fire, i get the error message: "Function is not defined= ". = How can i debug it? As far i can see, it should work. :) -- Regards Konrad Viltersten K Viltersten wrote on 19 mei 2008 in comp.lang.javascript: > I decl... DEFINE and reboot Hello, I'm trying to reinstall a OpenVMS 8.3 on a AS800. I try to create a logical name like DISK$USERS to create users home directories. I have tried : $CREATE/SYSTEM DISK$USERS SYS$SYSROOT:[USERS] and I can use this logical name to acces to SYS$SYSROOT:[USERS] but this logical name is not permanent. If I hve understand, create/system writes this logical name in a file. Thus, why this logical name is erased when AS800 is stopped ? Regards, JKB -- Le cerveau, c'est un v�ritable scandale �cologique. Il repr�sente 2% de notre masse corporelle, mais disperse � lui seul 2...

Preprocessor defines
Hi, This might be OT... Are there preprocessor defines in the C++ standard, such as __FILE__, __LINE__, __NAMESPACE__, __FUNCTION__, ec? If there is, were can I find a list? If there isn't, does anyone know of a good list for those defines under Gcc (3.4 <=)? -- Pelle Pelle Beckman wrote: > Hi, > > This might be OT... > > Are there preprocessor defines in the C++ standard, > such as __FILE__, __LINE__, __NAMESPACE__, __FUNCTION__, ec? > If there is, were can I find a list? > > If there isn't, does anyone know of a good list > for those defines ...

where should this function defined?
hi, I have worked mainly in C. I started programming in C++ just 2 weeks ago. supoose following classes class A { ... //some members ... }; class B { ........... ........... //other members A a[10]; .......... }; Now while updating my project, I need a new function which should be defined in class A....but it need to acces private members of class B..... what should I do? On Jun 14, 3:57=A0pm, Tagore <c.lang.mys...@gmail.com> wrote: > hi, > =A0 =A0 I have worked mainly in C. I started programming in C++ just 2 > weeks...

regarding #define
I have come across some preprossor statements, such as #define PPTR_int #define PPTR_str #define DDAR_baddr & #define DDAR_caddr & What do they mean, but when i compile the code with these i am not getting any errors . How about the #define format. " #define variable constant" , what the meaning of the first four #define's with out constant value. Why the compiler is not giving errors. Thanks, Vikas. venkat said: > I have come across some preprossor statements, such as > > #define PPTR_int > #define PPTR_str > #define DDAR_baddr & >...

#define constants
I think I read somewhere that #define constants in the style #define SOMETHING 6 are evaluated to long or unsigned long, depending on the situation and not int. Ioannis Vranos wrote: > I think I read somewhere that #define constants in the style > > > #define SOMETHING 6 > > > are evaluated to long or unsigned long, depending on the situation and > not int. .... Is that true? On 2008-04-03 15:33:28 -0400, Ioannis Vranos <ivranos@nospam.no.spamfreemail.gr> said: > Ioannis Vranos wrote: >> I think I read somewhere that #define constants in the...

#define #3
Hi all, What is the scope of preprocessor #define? Does it depends on the compiler? Thanks Ivan "Ivan" <idiprima@hotmail.com> wrote: > What is the scope of preprocessor #define? From that point on to the end of the file, or to a corresponding #undef if there is one. > Does it depends on the compiler? No. Richard On Jan 31, 4:21 pm, "Ivan" <idipr...@hotmail.com> wrote: > Hi all, > > What is the scope of preprocessor #define? > Does it depends on the compiler? anything below the #define line until the end of file, it does not depend f...