C problems

Chris Torek chris at mimsy.UUCP
Wed Jun 7 14:47:56 AEST 1989


>In article <13566 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer)
>writes:
>>... since this use of [] is a special case which exists nowhere
>>else in the language (it works *only* for formal arguments), it may be
>>less confusing to stick with "char **argv" after all.

In article <8639 at chinet.chi.il.us> les at chinet.chi.il.us (Leslie Mikesell)
writes:
>Umm, isn't that the same as:
>
>char *list[] = { "one", "two", "three", 0 };
>
>which seems to work as a global definition.

No, it is not the same---it only looks the same to the casual observer.
As Karl stated, `char *argv[]' is a special case because argv is a
formal parameter.  A C compiler is required silently to pretend that
you actually wrote `char **argv'.  That is:

	char *list[] = { 0, "hello", 0 };

	void foo() { (void) main(2, list); }

	int main(int argc, char *argv[]) {
		if (argc > 1) puts(argv[1]); else foo();
		return 0;
	}

is treated by the compiler as though argv (and only argv) were declared
with

	int main(int argc, char **argv) {

The declaration for `list' is *not* altered, because it is not a formal
parameter.
-- 
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