473,811 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#if (defined(__STDC __) && !defined(NO_PRO TOTYPE)) || defined(__cplus plus)

Hello,

Could anyone explain me the following preprocessor sentences:

----------------------------------------------------------------

#if (defined(__STDC __) && !defined(NO_PRO TOTYPE)) || defined(__cplus plus)
# define _USING_PROTOTYP ES_ 1
# define _ANSI_ARGS_(x) x
# define CONST const
# ifdef __cplusplus
# define VARARGS (...)
# else
# define VARARGS ()
# endif
#else
# define _ANSI_ARGS_(x) ()
# define CONST
#endif

#undef EXTERN
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif

-----------------------------------------------------------------

I know that __STDC__ means: "the compiler is C compatible"
I know that __cplusplus means: "the compiler does C++ compilation"

But I wonder what are NO_PROTOTYPE and _USING_PROTOTYP ES_.
Do they refer to the prototypes put in the .h ???
Are there compilers which doesn't accept prototypes ?
How do they do, then ?

Where do I find these preprocessor on the web ? No luck on Google...

So I underdstand:
if the compiler is ANSI C and does accept prototypes, or if the compiler
is C++...
let's use prototypes !
replace _ANSI_ARGS_(x) with x
....

About VARARGS...
Why is there a condition ? I believed that, for functions with an
undetermined number of parameters, the syntax was the same in C and C++
(both use dot-dot-dot): function(parame ter,...)

# define _ANSI_ARGS_(x) () ?????????

Well, if I have a prototype like
EXTERN void
surface_set_sha der _ANSI_ARGS_((Su rface *surface,
void *surf_desc,
Shader *shader));
I have to remplace it with
EXTERN void surface_set_sha der(); ???
What about parameters ??
THANKS A LOT FOR HELP !!
Nov 15 '05 #1
1 8461
Oodini <sv**********@f ree.fr> writes:
Could anyone explain me the following preprocessor sentences:

----------------------------------------------------------------

#if (defined(__STDC __) && !defined(NO_PRO TOTYPE)) || defined(__cplus plus)
# define _USING_PROTOTYP ES_ 1
# define _ANSI_ARGS_(x) x
# define CONST const
# ifdef __cplusplus
# define VARARGS (...)
# else
# define VARARGS ()
# endif
#else
# define _ANSI_ARGS_(x) ()
# define CONST
#endif

#undef EXTERN
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
-----------------------------------------------------------------

I know that __STDC__ means: "the compiler is C compatible"
I know that __cplusplus means: "the compiler does C++ compilation"


Right. (As far as this newsgroup is concerned, __cplusplus is a macro
that the implementation is not allowed to define.)
But I wonder what are NO_PROTOTYPE and _USING_PROTOTYP ES_.
Do they refer to the prototypes put in the .h ???
Are there compilers which doesn't accept prototypes ?
How do they do, then ?


Those are non-standard macros. They must be defined in some
application-specific header, or possibly by your compiler.

It looks like this code was designed to work around problems with very
old non-conforming implementations . Today, you're very unlikely to
run across a C compiler that doesn't support prototypes, or that
doesn't conform at least to the C89/C90 standard. I'd be surprised to
see *any* compiler that defines __STDC__ but doesn't support
prototypes.

Note that testing __STDC__ doesn't necessarily guarantee that your
compiler is conforming; it merely indicates that it *claims* to be
conforming. The standard requires any conforming implementation to
define __STDC__ (the required value changed from C89/C90 to C99), but
obviously it can't place any requirements on non-conforming compilers.
A non-conforming compiler doesn't become any more non-conforming
because it defines __STDC__.

As for the VARARGS macro, the <stdarg.h> header and the "..." syntax
have been standard C since C89/C90, and again, you're not likely to
run into a compiler that doesn't support it. But this feature was, I
believe, an invention of the ANSI C committee. The usual way to
define a printf-like function before that was to use the (now
obsolete) <stdargs.h> header.

It's very likely that you can safely rip out most of these tests, and
unconditionally use prototypes, "...", and <stdarg.h>. But you should
check what platforms you need to support before trying it -- *and* you
need to decide whether cleaning up the code is worth the effort and
the risk of accidentaly breaking something. The old forms are still
supported, so you might just want to leave things alone; in fact I'd
recommend it unless you have a specific reason to fix the code.

--
Keith Thompson (The_Other_Keit h) 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.
Nov 15 '05 #2

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

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.