void*
Rex Jaeschke
rex at aussie.UUCP
Tue Aug 14 08:32:28 AEST 1990
Re the handling of void * in memchr, etc. Doug Gwyn writes:
>That could be avoided by defining the function as
> void *memchr(const char *s, int c, unsigned int n)
>which works because of the "same representation" requirement.
I like Doug's suggestion but it did raise another question.
It's obviously useful to put a prototype in a header and include it
at the site of every call. However, it's also a good idea to include
it where the function is actually defined. If one uses Doug's
approach, will the compiler cough or not? For example:
void *memchr(const void *s, int c, unsigned int n);
void *memchr(const char *s, int c, unsigned int n)
{
/*...*/
}
I tried this on 6 DOS-based compilers all of which CLAIM to be
either ANSI-conformant or VERY close and they came up 3/3 on whether
the two function declarations were "compatible" (I'm not sure that's the
correct term to use here though).
Certainly void * and char * are required to have identical
representation. However, the two types are different types. Should a
REAL ANSI C compiler complain or not?
Rex
----------------------------------------------------------------------------
Rex Jaeschke | Journal of C Language Translation | C Users Journal
(703) 860-0091 | 2051 Swans Neck Way | DEC PROFESSIONAL
uunet!aussie!rex | Reston, Virginia 22091, USA | Programmers Journal
----------------------------------------------------------------------------
Convener of the Numerical C Extensions Group (NCEG)
----------------------------------------------------------------------------
More information about the Comp.std.c
mailing list