[comp.lang.c] Prototyping Question

cm315a@socrates.umd.edu (cmis 315 section 4011) (06/14/91)

Here's a question on prototyping that has me (and the compiler)
baffled.  I have a function that takes one, or more parameters. If I
decalre it as:  void funct(char *, ... ) the calls to it with one or two
(or more) parameters passes without errors, but when the compiler
comes to the function itself, I get an error - not enough parameters. 
 
But on the otherhand if I declare it as: void funct(char *, int), the
calls to the function with one parameter cause an error.  Yes, the
prototype, the calls, and the definition of the function are in the
same file, or use the same header.h file as the declaration.
 
How does one get around this type of behavior? For the curious, it is
a call to an error handler, the error message, and an optional error
number - much like a printf() call.
 
- mike   cm315a@socrates.umd.edu [

grover@big-joe.cs.unlv.edu (Kevin Grover) (06/15/91)

In article <1991Jun14.122200.3710@socrates.umd.edu>, cm315a@socrates.umd.edu (cmis 315 section 4011) writes:
) 
) Here's a question on prototyping that has me (and the compiler)
) baffled.  I have a function that takes one, or more parameters. If I
) decalre it as:  void funct(char *, ... ) the calls to it with one or two
) (or more) parameters passes without errors, but when the compiler
) comes to the function itself, I get an error - not enough parameters. 
)  
) But on the otherhand if I declare it as: void funct(char *, int), the
) calls to the function with one parameter cause an error.  Yes, the
) prototype, the calls, and the definition of the function are in the
) same file, or use the same header.h file as the declaration.
)  
) How does one get around this type of behavior? For the curious, it is
) a call to an error handler, the error message, and an optional error
) number - much like a printf() call.
)  
) - mike   cm315a@socrates.umd.edu [

What compiler??  I use that sort of prototype all the time on PC (Turbo C,
Borland C++) and UNIX (gcc).  I have had no problems.

-- 
  +---------------------------+-----------------------------------------------+
  | Kevin O. Grover           | UNLV Computer Science and Electrical Eng.     |
  | grover@cs.unlv.edu        | ISRI - Information Science Research Institute |
  | 73627.1677@compuserve.com | 4505 S. Maryland Parkway, Las Vegas NV 89154  |
  +---------------------------+-----------------------------------------------+

wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) (06/15/91)

In article <1991Jun14.122200.3710@socrates.umd.edu> cm315a@socrates.umd.edu (cmis 315 section 4011) writes:
>Here's a question on prototyping that has me (and the compiler)
>baffled.  I have a function that takes one, or more parameters. If I
>decalre it as:  void funct(char *, ... ) the calls to it with one or two
>(or more) parameters passes without errors, but when the compiler
>comes to the function itself, I get an error - not enough parameters. 

How is the function defined? It should be defined as

	void funct(char *first, ...) {
		va_list args;
		/* and any other local variables */

		va_start(args, first);
		/* access all arguments after first in a strictly
		   sequental order using va_arg(args). */
		va_end(args);
	}

Hope this helps.
-- 
Lars Wirzenius     wirzeniu@cc.helsinki.fi

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (06/16/91)

In article <1991Jun14.122200.3710@socrates.umd.edu>, cm315a@socrates.umd.edu (cmis 315 section 4011) writes:

> I have a function that takes one, or more parameters.  If I decalre
> it as:  void funct(char *, ... ) the calls to it with one or two (or
> more) parameters passes without errors, but when the compiler comes
> to the function itself, I get an error - not enough parameters.

> But on the otherhand if I declare it as: void funct(char *, int), the
> calls to the function with one parameter cause an error.

I'd need to see the prototype and the function definition (and,
preferably, a few calls of both types) to say much.  Most likely
explanation that comes to mind is that your prototype disagrees with
your definition.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu