home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18762 < prev    next >
Encoding:
Text File  |  1993-01-06  |  4.7 KB  |  93 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!wingnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Standard library functions and macros
  5. Message-ID: <1993Jan06.183334.4535@microsoft.com>
  6. Date: 06 Jan 93 18:33:34 GMT
  7. Organization: Microsoft Corporation
  8. References: <1993Jan2.191336.28542@taumet.com> <1993Jan04.231519.8704@microsoft.com> <1993Jan5.032555.12777@lucid.com>
  9. Lines: 82
  10.  
  11. In article <1993Jan5.032555.12777@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
  12. |In article <1993Jan04.231519.8704@microsoft.com>, jimad@microsoft.com (Jim Adcock) writes:
  13. ||> you going to make this work?  Seems to me you are requiring 
  14. ||> "C++ calling convention" of the standard-C functions called by the
  15. ||> C++ files, whereas the standard-C functions called from the "C" files
  16. ||> would have to follow "C" calling convention.  At the very least this
  17. ||> seems to me to be saying that you're requiring dual-entry stubs of
  18. ||> all the library functions.  And then how do these things coexist in
  19. ||> one library and get linked in correctly?  Can you point to even one
  20. ||> existing implementation that implements your proposed changes, and
  21. ||> which continues to allow mixed Cfile/C++file programs to be compiled and linked?
  22. |
  23. |I really don't understand Jim's concerns. All the vendors (of
  24. |Unix compilers) I've looked at take a similar approach to this problem.
  25. |As far as I can tell we would have no problem accomodating the currently
  26. |proposed X3J16 requirements.
  27.  
  28. The questions I have been raising is how well you accomodate the requirements
  29. of one of the two base docs -- namely the ANSI-C requirements.  I think you're
  30. saying there is no problem -- the C++ is simply blowing off the ANSI-C
  31. requirements.  I disagree with such an approach, because ANSI-C was 
  32. stated to be one of the base documents.  If you are not following this
  33. doc, you should be honest and remove it as one of the base docs.
  34.  
  35. |Lucid supplies a large collection of header files with its
  36. |compiler that allow use of the vendor (Sun) supplied C libraries. 
  37. |We share these headers between C++ and C without much problem.  
  38. |These headers check for #ifdef __cplusplus and "do the right thing".
  39. |When compiling C++ they insert extern "C" as appropriate.
  40. |In C++ modes we have also found it useful to define variants
  41. |of some of the C functions using the static inline technique
  42. |discussed previously by Steve.
  43. |
  44. |For example, in C++ modes our headers contain (after expansion of
  45. |some macros that allow us to control variation between compilation modes)
  46. |
  47. |    typedef void (*__sigtype)(int);
  48. |    typedef void (*__alt_sigtype)(int,int,struct sigcontext*,char*);
  49. |
  50. |    /* The C standard declaration */
  51. |    extern "C" __sigtype signal(int,__sigtype) ;
  52. |
  53. |    /* A variant expected by Sun programmers */
  54. |    extern "C++" inline __alt_sigtype signal(int __sig,  __alt_sigtype __h) {
  55. |        return (__alt_sigtype)signal( __sig, (__sigtype)__h) ;
  56. |    }
  57.  
  58. Seems to me that an inline call such as this requires a stub, either in
  59. the library, or compile-time generated, if the programmer does anything
  60. that prevents inline expansion of the inline function.  And such control
  61. over inline expansion is precisely the control permitted deliberately
  62. and explicitly in the base doc -- the ANSI-C base doc.  If C++ provides
  63. something analogous to the ANSI-C statement to the effect that macro
  64. implementations are backed up with "real" functions in the library.
  65.  
  66. |The extern "C" variant gets linked directly to Sun's C library
  67. |without any problems. We don't need stubs.
  68.  
  69. What happens when you take a type-correct pointer to the above function,
  70. for example, and invoke via that pointer?  I'd think you'd get a stub
  71. generated -- ie the compiler lays down an out-of-line function to implement
  72. the alt signal function.
  73.  
  74. |The variant was required because that is, in fact, the type of signal
  75. |according to the Sun man pages
  76. |
  77. |When compiling in strict ANSI C mode, the header just expands to
  78. |
  79. |    typedef void (*__sigtype)(int);
  80. |    __sigtype signal(int,__sigtype);
  81.  
  82. Seems to me that this example argues for my point-of-view -- that the
  83. ANSI-C function names should continue to remain reserved for implementation,
  84. so that implementations can continue to offer their implementation-specific
  85. variations as required above.  Taking it out in strict mode but then
  86. taking the name space back for the implementation in non-strict mode, as
  87. in your example above, is merely a ruse.  It doesn't buy the programmer
  88. any significant guarantee that the name space is available for their use.
  89. Either implementations should not contaminate the name space at all, or 
  90. if that is not practical, then the name space should remain the implementations.
  91. We should not resort to game playing, just to say "we passed conformance."
  92. Such games don't by the programmer anything real.
  93.