ANSI C prototypes
Stephen Clamage
steve at taumet.com
Wed Oct 31 03:06:03 AEST 1990
ptf at cs.bham.ac.uk (Paul Flinders <FlindersPT>) writes:
>given the file foo.c which contains code for a module within a program,
>foo.h which defines prototypes for routines in foo.c and bar.c which
>includes foo.h I tend to include foo.h in foo.c so that the compiler
>will tell me if I have been foolish enough to change a routines
>parameters without changing foo.c (the code in foo.c is not yet cast
>in stone so changes are a posibility). This works fine _except_ for
>varargs functions eg.
>in foo.h:
> extern void ddprintf(const char *fmt, ...);
>BUT in foo.c:
> void ddprintf(va_alist)
> va_dcl;
>this causes problems.
As well it should. What you show is not ANSI C, despite the Subject line
of your posting. It is the BSD C approach to variadic functions, which is
not quite the same as the ANSI approach. In ANSI C,
void ddprintf(const char *fmt, ...);
and
void ddprintf(va_alist);
are not at all the same. It sounds like you are using <varargs.h> with
an ANSI compiler, instead of using <stdarg.h>.
If you use the ANSI C <stdarg.h> header, the function delcaration in foo.h
and the function defintion in foo.c become identical. But you need to
decide if the function is to take a variable *list* of arguments, or *one*
argument of type va_list. The two notions are not the same. Refer to the
discussions of <stdarg.h>, printf() and vprint() in any good ANSI C text,
or in the Standard, for more details.
--
Steve Clamage, TauMetric Corp, steve at taumet.com
More information about the Comp.lang.c
mailing list