home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Standard library functions and macros
- Message-ID: <1993Jan2.191336.28542@taumet.com>
- Organization: TauMetric Corporation
- References: <BzFM01.CD@frumious.uucp> <1992Dec23.214139.24948@microsoft.com> <1992Dec25.014646.9364@lucid.com> <1992Dec29.213548.5661@microsoft.com> <9300302.725@mulga.cs.mu.OZ.AU>
- Date: Sat, 2 Jan 1993 19:13:36 GMT
- Lines: 60
-
- fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
-
- >jimad@microsoft.com (Jim Adcock) writes:
-
- >>The fact that macro implementations are allowed under ANSI reserves the
- >>entirety of the name space of a standard function to the library if
- >>the header is included. If the programmer doesn't like this, then
- >>the programmer is permitted to simply declare the function required
- >>out of the standard library, and just use that. Which your changes
- >>will also break.
-
- >... I think that perhaps you are overreacting a
- >little, Jim. Could someone who has actually read (or written ;-) the changes
- >confirm that they would not break
- > extern char *puts(const char *);
- > inti main() { puts("Hello world\n"); return 0; }
- >?
-
- Jim is correct on this point. The change says that you must include a
- standard header for standard functions, and that the results of providing
- your own declarations are undefined. The reasons for this are to allow
- implementors the freedom to use existing C libraries and declare the
- functions to be extern "C", or to write new library functions with C++
- linkage (or a mixture of both). A portable program cannot assume what
- choice was made. (I suppose the functions could use Fortran or PL/I
- linkage, for that matter.)
-
- If an implementation uses the same library for C and C++, which is
- true for current implemenations, you can successfully do this:
- extern "C" int puts(const char *);
- int main() { puts("Hello world\n"); return 0; }
- You are just not assured the code will work.
-
- Jim missing a point, I think. Let's say, under his scenario, that I
- create a class with a member function getchar. I am careful not to
- use <stdio.h>, and everything is fine. A later programmer wants to use
- stdio as well as my class library, and the code won't compile.
-
- We have (at least) two choices. Jim wants to leave the C headers alone,
- meaning that the names of all the C library functions are unavailable
- for use as class member functions. The choice which was adopted says
- that some existing C code would have to be modified under some C++
- implementations -- you might have to use standard headers instead of
- homebrew declarations of standard functions. I don't think you can make
- a case that either choice is just plain wrong; it is a judgement call.
- The C++ Committee made a judgement, and anyone is free to disagree.
-
- Jim also identified one "quiet change": If you take the address of a
- standard library function in C, the address will compare equal across
- compilation units. With the C++ change, inline versions of a standard
- function might (but might not) have different addresses in different
- compilation units.
-
- A few weeks ago I asked for analyses of this situation, or of any other
- problem associated with the change in C library rules for C++. I did
- not get any response. I renew the request. If the Committee has made
- a bad decision, this is the time to correct it.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-