More on pointers/arrays: Function A - (nf��

eich at uiuccsb.UUCP eich at uiuccsb.UUCP
Sat Apr 14 06:09:00 AEST 1984


#R:harvard:-21500:uiuccsb:9000021:000:622
uiuccsb!eich    Apr 13 14:09:00 1984

/**** uiuccsb:net.lang.c / harvard!brownell / 10:57 pm  Apr 10, 1984 ****/
    char *index (s, c)
	char s [], c;
    {
	while (*s != '\0' && *s != c)
	    ++s;				/* AARGH!! */
	return (*s == c ? s : NULL);
    }
/* ---------- */

Nothing wrong with this, except that it can cause array-as-lvalue
confusion: s is not an array.  Because of C's call-by-value semantics,
an array name used as an actual parameter (or equivalently, used in an
expression) is converted to a pointer to the first element of that
array.  Lax (actually, generalized) syntax for formal argument
declaration allows [] to be used where * is correct.



More information about the Comp.lang.c mailing list