Solved

What does __STDC__ mean to Visual C++ 5.0?

Posted on 1998-12-28
6
665 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:zebada
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:yonat
ID: 1181134
__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
 
LVL 6

Author Comment

by:zebada
ID: 1181135
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
 
LVL 2

Expert Comment

by:zyqwert
ID: 1181136
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:yonat
ID: 1181137
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
 
LVL 6

Author Comment

by:zebada
ID: 1181138
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
 
LVL 5

Accepted Solution

by:
yonat earned 100 total points
ID: 1181139
Thanks, and good luck.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question