🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1590

Re: void*

#1590
From: Rex Jaeschke
Date: Mon, 13 Aug 1990 22:32
39 lines
1974 bytes
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)
----------------------------------------------------------------------------
Technical Details
Message-ID: <43.UUL1.3#5077@aussie.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uunet!aussie!rex
References: <13530@smoke.BRL.MIL>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uunet!aussie!rex
From: rex@aussie.UUCP (Rex Jaeschke)
Newsgroups: comp.std.c
Subject: Re: void*
Message-ID: <43.UUL1.3#5077@aussie.UUCP>
Date: 13 Aug 90 22:32:28 GMT
References: <13530@smoke.BRL.MIL>
Organization: Journal of C Language Translation
Lines: 39