[comp.lang.c++] TC++ include file madness

defaria@hpclapd.HP.COM (Andy DeFaria) (11/09/90)

I recently set up a 286 DOS 3.3  PC to run Turbo  C++ Professional.  I'm in
the process of learning C  better and also  learning C++.  I have installed
TC under a directory  called \system so  I have  \system\tc, etc.  In going
through  the first   example I    copied  the point.cpp from   the examples
directory to my directory (\andy).   When  I compile it I  get an error.  I
have:

#include <iostream.h>

which in turn includes <mem.h> (and the  include in iostream.h  does indeed
say "#include <mem.h>").  The TC compiler says that it can't open mem.h.  I
have  the "Include   Directories"  set   to \system\tc\include   and   both
iostream.h and mem.h reside there.  If I change the code to:

#include <mem.h>
#include <iostream.h>

I  see that the compiler can  find  mem.h and compiles  it without a hitch.
Then it compiles iostream.h and fails again saying it can't find mem.h!!!

What's going on here?

ahuttune@niksula.hut.fi (Ari Juhani Huttunen) (11/12/90)

In article <58170036@hpclapd.HP.COM> defaria@hpclapd.HP.COM (Andy DeFaria) writes:

>#include <mem.h>
>#include <iostream.h>

>I  see that the compiler can  find  mem.h and compiles  it without a hitch.
>Then it compiles iostream.h and fails again saying it can't find mem.h!!!

>What's going on here?

It so happens I have also had trouble with iostream.h and mem.h .
In mem.h there is a code fragment:
#ifdef __cplusplus
extern "C" {
#endif
etc... (I hope I haven't violated any copyright laws..)
This compiles fine with C and C++ modes with both integrated and stand-alone
compilers. BUT when I have a file that includes a file that includes iostream.h
that includes mem.h this DOES NOT compile fine(C++ mode). (With stand-alone
compiler there are no problems.) What gives?
(I suspect the compiler in some way changes from C++ to C mode during 
compilation, but I'm not sure; also in the process it does not undefine
__cplusplus. This may have something to do with the fact that my c++ files
all end in .c and not .cpp. I HAVE the "compile always with C++ mode" option
on.)

ps. What does extern "C" { } mean?
--
  ___  ___  ___  ___  ___  ___  ___  ___  ___  
__I I__I I__I I__I I__I I__I I__I I__I I__I I  Thank you 
 Ari Huttunen    (ahuttune@niksula.hut.fi)  I   for not smoking!
____________________________________________I    <Robocop>

watson@spock (Steve Watson) (11/12/90)

In article <AHUTTUNE.90Nov11175357@wonderwoman.hut.fi> ahuttune@niksula.hut.fi (Ari Juhani Huttunen) writes:
>It so happens I have also had trouble with iostream.h and mem.h .
>In mem.h there is a code fragment:
>#ifdef __cplusplus
>extern "C" {
>#endif
>etc... (I hope I haven't violated any copyright laws..)
[...............]
>ps. What does extern "C" { } mean?
> Ari Huttunen    (ahuttune@niksula.hut.fi)

extern "C" means that the functions prototyped inside the braces are to
be treated as standard C, not C++ i.e. prepend underscore, do NOT perform
name-mangling when writing them to the .obj.  If this is documented in the
TC++ manuals, then I MISSED IT!  The closest it comes to this is to tell
you about the 'cdecl' keyword, which actually only instructs the compiler
to use C parameter-passing conventions (as opposed to Pascal).  I had to
find this out by trial-and-error, i.e. the linker would bomb, claiming it
couldn't find the function name, editting the .obj file revealed that
the name was in fact being mangled, so I looked at one of the library
include files and, lo-and-behold, they all contained this 'extern "C" {}'
construct!  I stuck that in, and, presto! all was hunky-dory.

BTW, another TC++ include file hiccup: in 'string.h', I believe there is
a misplaced #endif about half-way thru the file, something like this
(from memory, I'm not on my PC):

#ifndef	_STDC_
#define	stricmp		strcmpi		* defining non-std aliases for
#define	strnicmp	strncmpi		* string compare funcs

.... other string func protypes & macro def'ns follow e.g. 'strlwr',
but the #endif isn't until the end of the file, so you get a lot
of "no prototype" errors etc. if you've used those functions.

Sigh.  It's SO annoying to install this brand spanking new compiler
and find that it barfs ALL OVER code that's been working for months...

-- 
====================== disclaimer ===============================
"Blame me, not the Company I keep..." - Steve Watson
UseNet: mitel!spock!watson@uunet.uu.net

jbuck@galileo.berkeley.edu (Joe Buck) (11/13/90)

In article <5279@watson>, watson@spock (Steve Watson) writes:
|> extern "C" means that the functions prototyped inside the braces are to
|> be treated as standard C, not C++ i.e. prepend underscore, do NOT perform
|> name-mangling when writing them to the .obj.  If this is documented in the
|> TC++ manuals, then I MISSED IT!

This is part of the C++ language as of version 2.0.  Any compiler that does
NOT implement this is broken.  It's not up to Borland to give you an
introductory language test; buy a good C++ book and read it.


--
Joe Buck
jbuck@galileo.berkeley.edu	 {uunet,ucbvax}!galileo.berkeley.edu!jbuck