Solved

What does __STDC__ mean to Visual C++ 5.0?

Posted on 1998-12-28
6
650 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now