kdq@demott.COM (Kevin D. Quitt) (07/03/90)
My thanks to: gordon@sneaky.lonestar.org Gordon "UNPORTABLE" Burditt donp@novell.com don provan... karl@haddock.ima.isc.com Karl Heuer for helping me see the (what should have been) obvious. BTW, my compiler accepts: int foo( int, ... ); but rejects: int foo(...); and calls the ... a syntax error. Anyone: is the above declaration ANSI, or K&R, or none of the above? -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last 96.37% of all statistics are made up.
steve@taumet.com (Stephen Clamage) (07/03/90)
In article <351@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes: > BTW, my compiler accepts: >int foo( int, ... ); > but rejects: >int foo(...); > and calls the ... a syntax error. Anyone: is the above declaration >ANSI, or K&R, or none of the above? Your compiler is correct. ANSI C requires at least one parameter declaration to precede the ellipsis (...). It also requires the ellipsis notation in the prototype and definition of any function which takes a variable number of arguments (in a conforming program). Of course, the ellipsis must occur at the end of the parameter list. This is covered in the syntax section of 3.5.4 of the ANSI standard, and elaborated in 3.5.4.3. The feature interacts with the typedef and macros in standard header <stdarg.h>, in section 4.8. This means that there is no portable way to declare and use a function which may take zero or more arguments, or whose first argument might be of any type. How does one write a function which might or might not have a first argument of any type? However you do it, I suspect the program would be very difficult to understand and maintain. Some re-thinking of the program design would be in order. -- Steve Clamage, TauMetric Corp, steve@taumet.com
dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (07/04/90)
In article <300@taumet.com> steve@taumet.UUCP (Stephen Clamage) writes: > >How does one write a function which might or might not have a first >argument of any type? However you do it, I suspect the program >would be very difficult to understand and maintain. Some re-thinking >of the program design would be in order. >-- The behavior of the function can be determined by the value of a global variable. The database package we use does something like this --- most of the database access functions take an optional database number which is needed only if you have opened more than one database and have not called d_setdb (int database_number) which tells the database library to use the given database_number for all future database access functions. The database library knows if this is the case by checking values in db_global, a global variable that stores all of the global database information. I don't agree with this design decision, but it isn't horrible either. -- Dave Eisen Home: (415) 323-9757 dkeisen@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043
colin@array.UUCP (Colin Plumb) (07/06/90)
In article <351@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes: >BTW, my compiler accepts: > >int foo( int, ... ); > > but rejects: > >int foo(...); > > and calls the ... a syntax error. Anyone: is the above declaration >ANSI, or K&R, or none of the above? ... is an ANSI invention; no use of it is K&R. However, ANSI requires at least one argument of a known type before the ... Consider: what type of argument would you ask for first? You've got no prior arguments to conditionalise on, so it's got to be a fixed type. So why not declare it? (Well, you could use a global/static variable, but that's too sick for words.) -- -Colin