an elementary question concerning double indirection

Martin Weitzel martin at mwtech.UUCP
Wed Feb 28 21:13:56 AEST 1990


In article <8146 at hubcap.clemson.edu> kaires at hubcap.clemson.edu (Robert G Kaires) writes:
> this function has the syntax:
>             double strtod(const char *s, char **endptr);
>
>Why is endptr a pointer to a pointer (and not just a pointer)?
>Unfortunately the description of double indirection is poorly explained
>in my manuals, and no description of how to use this function is given.

Yes, this is a constant source of trouble for novice C programmers.

	********************************************************
NOTE:   ** If you find a double pointer as formal argument    **
	** in the description of some library function, this  **
	** often means you have to supply the ADRESS of a     **
	** (single) pointer variable! Furthermore pointers    **
	** to C-struct-s as formal arguments often means you  **
	** have to supply the adress of a struct-variable.    **
	** Furthermore pointers to char (char *) often means, **
	** that an "array of char" (char foo[SIZE]) would be  **
	** appropriate, when the function is called (%).      **
	********************************************************

Please, do NOT take the above as general rule (eg there may well be
situations where a double pointer formal argument needs a double
pointer as actual parameter a.s.o.), but as a "warning light" which
is switched on in your brains, if you read the manual!

(%): If the library function *writes* to the location, the
pointer points to, make sure "SIZE" is sufficient (and don't
forget the terminating '\0'-Byte!).

[the correct answer for the presented problem was
 allready given by another poster, I'll delete it]
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.lang.c mailing list