Problems with IBM RS6000 C compiler

Stephen Clamage steve at taumet.com
Tue Aug 7 01:37:07 AEST 1990


diamond at tkou02.enet.dec.com (diamond at tkovoa) writes:

>In article <476 at mtndew.UUCP> friedl at mtndew.UUCP (Stephen J. Friedl) writes:
>>	extern int stat(char *filename, struct stat *stptr);
>>Shouldn't the "filename" argument be const qualified?

>But if const is included, it would break a lot of code that presently
>works under Unix(tm) operating system.  (I'm not sure what Posix(tm?)
>standards say.)

No, it wouldn't break any code.  A const-qualified parameter type may
be passed a non-const argument, but the reverse is not true.  If
the parameter is not const-qualified, you cannot pass it a literal
string without a cast.  So the *failure* to const-qualify will break
existing code.  That is, with the above prototype,
	r = stat("myfile", &data);
is illegal under ANSI.
But given
	extern int stat(const char *, struct stat *);
			^^^^^
the following are legal:
	char *fname; /* not const */
	stat(fname, &data);
	stat("myfile", &data);
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list