noalias, again (was extern const)

Chris Torek chris at mimsy.UUCP
Mon Mar 21 02:44:55 AEST 1988


In article <7485 at brl-smoke.ARPA> gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
>Basically, "noalias" is ... [long description deleted]
>
>I think I got that substantially right, although I may have messed
>up a few details.  Hey, I don't plan to use [noalias]!

But you do plan to use the standardised language.  If noalias is in the
standard, and you do not understand noalias, you cannot use the C
library effectively, because it *does* use noalias, and you may not
ignore that.

For instance, the latest draft says that the prototype declaration of
`strcpy' is

	char *strcpy(noalias char *dst, noalias char *src);
	/* or perhaps char *noalias dst, but that is irrelevant here */

What this means to you, the programmer calling strcpy, is that the
following code, which used to be legal and predictable, is now illegal
and unpredictable [I think] BUT THE COMPILER CANNOT WARN YOU:

	f() {
		char buf[SIZE];
		int n;
		...
		/* remove leading junk (n < strlen(buf)) */
		(void) strcpy(buf, buf + n);

You must understand `noalias' to know why this has become illegal
(which may only demonstrate that I do not understand it myself, if
it is in fact legal under the above declaration).

The point is that the standard library is now bestrewn with `noalias'
declarations; these declarations make promises to the compiler; and you
as a programmer are obligated to keep these promises, so you must know
what they are and, when necessary, change your code where it violates
them.  The C library you have been using makes no such promises.  There
has been nothing to violate; now there is.

If all the `noalias'es were removed from the library standard, you
could start ignoring noalias.

But....

Someday, somewhere, someone will supply you with an existing body
of code---perhaps a library---that *does* use noalias, and you will
have to understand noalias to use or modify that code.  If it is
a library and supplied in object form, you will not even have the
option of removing all the `noalias' modifiers.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list