function declarations

Clayton Cramer cramer at optilink.UUCP
Sat Dec 10 05:44:39 AEST 1988


In article <11480014 at hpsmtc1.HP.COM., swh at hpsmtc1.HP.COM (Steve Harrold) writes:
. Re: Function prototypes
. 
. The MSC /Zg switch is useful, but doesn't do everything.  For example,
. 
. 1) All parameters that are structs or pointer to structs get translated to
.    "struct UNNAMED".  If you then use these function prototypes in your code,
.    you will get compile-time messages announcing a type mismatch between the
.    the non-existent "struct UNNAMED" and whatever struct is actually in your
.    code.  For MSC, this is a warning, and the compilation succeeds.  For
.    Turbo C, this is an error, and compilation fails.  For older (non-ANSI)
.    compilers, there is no message.

Easy solution: always create a structure tag when you do a typedef.  I'm
amazed how many people don't realize that struct and enum optionally
accept a tag.  Use the tag, and the /Zg switch will produce useful
prototypes.

. 2) If you use <varargs.h. in your parameter list, the function prototype that
.    is generated names a type "va_alist", rather than inserting the "..." string
.    that ANSI uses to denote optional (varargs) parameters.  Again, the
.    compiler complains about the mismatch (usually "too many parameters").

ANSI C uses stdarg.h, not varargs.h.  Use stdarg.h in Microsoft C, and
the /Zg switch will produce ... in a form that is useful.

. Steve Harrold			...hplabs!hpsmtc1!swh

-- 
Clayton E. Cramer
{pixar,tekbspa}!optilin!cramer          (Note new path!)



More information about the Comp.lang.c mailing list