Solved

What does __STDC__ mean to Visual C++ 5.0?

Posted on 1998-12-28
6
663 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

829 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