Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What does __STDC__ mean to Visual C++ 5.0?

Posted on 1998-12-28
6
Medium Priority
?
681 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 400 total points
ID: 1181139
Thanks, and good luck.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

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