home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20142 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.2 KB  |  57 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Possible bug in BC 3.1: ellipsis in proto argument list
  5. Message-ID: <1993Jan24.161612.18120@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1993Jan24.050036.26236@ns1.cc.lehigh.edu>
  8. Date: Sun, 24 Jan 1993 16:16:12 GMT
  9. Lines: 46
  10.  
  11. sg0d@ns1.cc.lehigh.edu (STEPHEN R. GILBERT) writes:
  12.  
  13. >I seem to have found a bug in my Borland C++ 3.1 compiler.  I narrowed
  14. >the problem down to the following prototype:
  15.  
  16. >void foo(...)
  17.  
  18. >If the above line is by itself in foo.h and I run:
  19. >bcc -P -c foo.h
  20. >It compiles without mishap.  If you're wondering: -P is to force a C++
  21. >compile and -c is compile to .obj only.
  22.  
  23. >The problem is that if I try to compile without the -P, that is,
  24. >compile in regular, standard BC 3.1, I get the error message:
  25. >) expected
  26.  
  27. The compiler is correct.  This reflects a difference between C and C++.
  28.  
  29. In Standard C, a function must have at least one argument declared before
  30. the ellipsis.  On the other hand, you may declare a function with
  31. completely unspecified arguments by using empty parens.  In C++, the
  32. empty parens mean the function takes no arguments.  To say a function
  33. has completely unspecified arguments in C++, use just the ellipsis.
  34. Examples:
  35.  
  36.     void f1(int, ...);  /* C and C++: f1 takes one int plus other
  37.                 unpsecified args */
  38.  
  39.     void f2();    /* C: no data about the arguments to f2 */
  40.             /* C++: f2 takes no arguments */
  41.  
  42.     void f3(...);    /* C++: no data about the arguments to f3 */
  43.             /* C: illegal */
  44.  
  45. You can't write function f3 in C++, although you can declare it.  There is
  46. no (portable) way to retrieve arguments when only an ellipsis is declared.
  47. You need to use the <stdarg.h> macros which require a declared argument.
  48. If you try to use the C trick of defining the real function with its real
  49. arguments, your program won't link, since foo(...) and foo(int), for
  50. example, are different functions.  The ellipsis-only notation is to allow
  51. linking to functions written in another language (not C++) where the
  52. calling conventions just happen to work and you are willing to forgo type
  53. checking and default promotion of actual arguments.
  54. -- 
  55.  
  56. Steve Clamage, TauMetric Corp, steve@taumet.com
  57.