Randy said:
Jordan Abel wrote
int main(){
char string[20]={""};
string[20] = {" connected "};
}
In addition to the more helpful comments you have already received,
"string" is an identifier reserved for use by the implementation, and
you should thus not use it. (IIRC, that statement only applies if
you've included <string.h>.)
His use of the identifier does not have external linkage, nor is at file
scope, so he should be fine, at least if he hasn't included string.h or
stdlib.h [possibly even if he has, but i don't know in that case]
Irrelevant. There is nothing to prevent ISO C 200x from using
that identifier, because it is reserved explicitly for such use.
So, a new compiler comes along, and suddenly the above code
stops working. With or without string.h.
You're wrong in the sense that C99 does not say that (a hypothetical
future C standard might, but then again that might do anything). Here is
everything relevant to that:
7.1.3:
"Each macro name in any of the following subclauses (including the
future library directions) is reserved for use as specified if any of
its associated headers is included; unless explicitly stated otherwise."
"All identifiers with external linkage in any of the following
subclauses (including the future library directions) are always reserved
for use as identifiers with external linkage."
"Each identifier with file scope listed in any of the following
subclauses (including the future library directions) is reserved for use
as a macro name and as an identifier with file scope in the same name
space if any of its associated headers is included."
7.1.4: "Any function declared in a header may be additionally
implemented as a function-like macro defined in the header [...]"
7.26.10: "Function names that begin with str and a lowercase letter may
be added to the declarations in the <stdlib.h> header."
7.26.11: "Function names that begin with str, mem, or wcs and a
lowercase letter may be added to the declarations in the <string.h> header."
Therefore, an identifier mentioned in a "future directions" clause is
reserved only if the associated header is included or if used with
external linkage or both.
A program is free to call anything "string" if it does not give the
identifier external linkage and if it does not include <string.h> or
<stdlib.h>. Whether that is *wise* is another matter, since it's easy to
break things by adding a header.
S.