"Noalias" warning and questions
Arthur David Olson
ado at elsie.UUCP
Fri Feb 12 04:44:05 AEST 1988
X3J11 has now mailed out copies of the January 11, 1988 versions of the
Draft Proposed C Standard and the Rationale.
It looks as if folks planning to make use of standard library functions
won't have the luxury of simply ignoring "noalias". The Rationale (which
contains what were to me enlightening words on "noalias") notes that
"Declaring a pointer-type function parameter to be noalias enjoins the caller
of that function to assure that the object referenced by that pointer overlaps
with no other parameter object." Since many standard library functions
have prototypes that declare arguments to be "noalias", you'll need to
ensure that there's no such overlap when you call them.
Now a bit of background for a few questions. Here are two function prototypes
from the proposed Standard:
int strcmp(const noalias char *s1, const noalias char *s2);
void perror(const noalias char *s);
1. Does the program
#include "stdlib.h"
main() {
char array[3];
array[0] = '\0';
return strcmp(array, array);
}
violate any constraints? If so, must the compiler detect the violation?
2. Does the program
#include "stdlib.h"
main() {
char array[3];
char * p, q;
array[0] = '\0';
p = array;
q = array;
return strcmp(p, q);
}
violate any constraints? If so, must the compiler detect the violation?
3. Remembering that identical string literals may not be distinct, might the
program
#include "stdlib.h"
main() {
return strcmp("walla", "walla");
}
violate any constraints? If so, must the compiler detect the violation?
4. What is the "noalias" in the "perror" declaration designed to do?
--
ado at vax2.nlm.nih.gov ADO, VAX, and NIH are Ampex and DEC trademarks
More information about the Comp.lang.c
mailing list