home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Possible bug in BC 3.1: ellipsis in proto argument list
- Message-ID: <1993Jan24.161612.18120@taumet.com>
- Organization: TauMetric Corporation
- References: <1993Jan24.050036.26236@ns1.cc.lehigh.edu>
- Date: Sun, 24 Jan 1993 16:16:12 GMT
- Lines: 46
-
- sg0d@ns1.cc.lehigh.edu (STEPHEN R. GILBERT) writes:
-
- >I seem to have found a bug in my Borland C++ 3.1 compiler. I narrowed
- >the problem down to the following prototype:
-
- >void foo(...)
-
- >If the above line is by itself in foo.h and I run:
- >bcc -P -c foo.h
- >It compiles without mishap. If you're wondering: -P is to force a C++
- >compile and -c is compile to .obj only.
-
- >The problem is that if I try to compile without the -P, that is,
- >compile in regular, standard BC 3.1, I get the error message:
- >) expected
-
- The compiler is correct. This reflects a difference between C and C++.
-
- In Standard C, a function must have at least one argument declared before
- the ellipsis. On the other hand, you may declare a function with
- completely unspecified arguments by using empty parens. In C++, the
- empty parens mean the function takes no arguments. To say a function
- has completely unspecified arguments in C++, use just the ellipsis.
- Examples:
-
- void f1(int, ...); /* C and C++: f1 takes one int plus other
- unpsecified args */
-
- void f2(); /* C: no data about the arguments to f2 */
- /* C++: f2 takes no arguments */
-
- void f3(...); /* C++: no data about the arguments to f3 */
- /* C: illegal */
-
- You can't write function f3 in C++, although you can declare it. There is
- no (portable) way to retrieve arguments when only an ellipsis is declared.
- You need to use the <stdarg.h> macros which require a declared argument.
- If you try to use the C trick of defining the real function with its real
- arguments, your program won't link, since foo(...) and foo(int), for
- example, are different functions. The ellipsis-only notation is to allow
- linking to functions written in another language (not C++) where the
- calling conventions just happen to work and you are willing to forgo type
- checking and default promotion of actual arguments.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-