home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!lucid.com!lucid.com!jss
- From: jss@lucid.com (Jerry Schwarz)
- Subject: Re: Standard library functions and macros
- Message-ID: <1993Jan7.042121.23809@lucid.com>
- Sender: usenet@lucid.com
- Reply-To: jss@lucid.com (Jerry Schwarz)
- Organization: Lucid, Inc.
- References: <1993Jan2.191336.28542@taumet.com> <1993Jan04.231519.8704@microsoft.com> <1993Jan5.032555.12777@lucid.com> <1993Jan06.183334.4535@microsoft.com>
- Date: Thu, 7 Jan 93 04:21:21 GMT
- Lines: 69
-
- I am going to respond to a few of the technical points.
-
-
- jss:
- |> |For example, in C++ modes our headers contain (after expansion of
- |> |some macros that allow us to control variation between compilation modes)
- |> |
- |> | typedef void (*__sigtype)(int);
- |> | typedef void (*__alt_sigtype)(int,int,struct sigcontext*,char*);
- |> |
- |> | /* The C standard declaration */
- |> | extern "C" __sigtype signal(int,__sigtype) ;
- |> |
- |> | /* A variant expected by Sun programmers */
- |> | extern "C++" inline __alt_sigtype signal(int __sig, __alt_sigtype __h) {
- |> | return (__alt_sigtype)signal( __sig, (__sigtype)__h) ;
- |> | }
- |>
-
- jimad:
- |> Seems to me that an inline call such as this requires a stub, either in
- |> the library, or compile-time generated, if the programmer does anything
- |> that prevents inline expansion of the inline function.
-
- If I call the "alt" version
-
- void handler(int,int,sigcontext*, char*) ;
- ...
- signal(0,handler) ;
-
- The compiler generates a direct call to the C function. No stub
- is layed down. If I do something that requires a function pointer
- [Sorry I'm using the types, but it's too confusing otherwise]
-
- __alt_sigtype (*paltsig)(int, __alt_sigtype)) = signal ;
-
- A (static) stub is created.
-
- jimad:
- |> And such control
- |> over inline expansion is precisely the control permitted deliberately
- |> and explicitly in the base doc -- the ANSI-C base doc.
-
- You keep saying this, but you don't explain how you arrive at that
- conclusion. What the C standard allows is being sure that a
- macro isn't in scope. It does not let you control whether the standard
- functions are inlined.
-
- jss:
- |> |The extern "C" variant gets linked directly to Sun's C library
- |> |without any problems. We don't need stubs.
- |>
- jimad:
- |> What happens when you take a type-correct pointer to the above function,
- |> for example, and invoke via that pointer? I'd think you'd get a stub
- |> generated -- ie the compiler lays down an out-of-line function to implement
- |> the alt signal function.
- |>
-
- I explicitly refered to the extern "C" variant.
-
- __sigtype (*psig)(int,__sigtype) = signal ;
- (*psig)(0,(__sigtype)0) ;
-
- The value stored in psig is a pointer into the C library,
- and a call is made directly to that function in the second line.
- Most of the standard library functions would not have variants.
-
- -- Jerry Schwarz
-