What does __STDC__ mean to Visual C++ 5.0?

I have three header files one containing the  following
pre-processor directives:

#ifdef __STDC__
#include <headerA.h>
#else
#include <headerB.h>
#endif

The other two:
headerA.h: contains function prototypes with parameters ie:
               int myfunc(int p1,char *p2);

headerB.h: contains function prototypes with no parameters ie:
               int myfunc(/*int p1,char *p2*/);


When I compile my program using MS Visual C++ 5.0, <headerB.h>
is included. I would like to have <headerA.h> included instead.

What do I need to set to make sure __STDC__ is set appropriately,
ie to include <headerA.h>?
Also what does __STDC__ actually mean to the compiler?

BTW: The actual header files that I am having trouble with
     are from Oracle 8.03 OCI in "oci.h":

#ifdef __STDC__
#include <ociapr.h>            // I think the 'a' stands for Ansi
#include <ociap.h>
#else
#include <ocikpr.h>            // I think the 'k' stands for Kernighan
#include <ocikp.h>
#endif

LVL 6
zebadaAsked:
Who is Participating?
 
yonatCommented:
Thanks, and good luck.
0
 
yonatCommented:
__STDC__ is defined iff the compiler is ANSI compliant. To make VC5 ANSI compliant, you should:
1. Make sure the source file that includes the header file has a .c extension.
2. Disable language extensions in the C/C++ tab of the Project Settings dialog.
0
 
zebadaAuthor Commented:
Thanks yonat, your answer confirms what I found (using *.c files and /Za option)

If I understand what you're saying, then is it true that I can't have a c++ source file that
includes a header that uses the directives indicated in the question, and still have the
<headerA.h> file included?

If this is so what I need to know is HOW can I get the right header (<headerA.h>) to be included without changing the header files (they're Oracle's not mine)?

Or should I not use these headers with c++?

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
zyqwertCommented:
The reason they have header b is for a compiler that doesn't understand function prototypes.  Since your compiler does, it is OK to use header a.  Here's how:

#ifndef __STDC__
#define __STDC__
#define NEED_TO_UNDEFINE
#endif
#include <oci.h>
#ifdef NEED_TO_UNDEFINE
#undef NEED_TO_UNDEFINE
#undef __STDC__
#endif

Now, anything else in <oci.h> which requires "real"  __STDC__ is at risk, but you won't have to edit Oracle's headers.
P.S. Chances are good you'll need to wrap the whole thing in extern "C".

0
 
yonatCommented:
Just do:

#ifdef __cplusplus
#ifndef __STDC__
#define __STDC__
#endif
extern "C" {
#endif
#include <oci.h>
#ifdef __cplusplus
}
#endif

The part about extern "C" is common practice. It is surprising Oracle haven't done it themselves. The part about __STDC__ is non-standard and ugly. If Oracle headers were more C++ friendly you wouldn't need that.
0
 
zebadaAuthor Commented:
Thanks yonat and zyqwert for your answers.

I finally settled on the following:

#if !__STDC__
#undef __STDC__
#define __STDC__ 1
#define NEED_TO_UNDEFINE
#endif
#include <oci.h>
#ifdef NEED_TO_UNDEFINE
#undef NEED_TO_UNDEFINE
#undef __STDC__
#define __STDC__ 0
#endif

This produces no warnings and allows existing headers that use the
#if !__STDC__ macro to work.  It breaks if I #undef __STDC__

100 points each sound OK?

Yonat, answer this one, Zyqwert answer the one with your name in the question in the
same category.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.