Pointer arithmetic

Tim Olson tim at proton.amd.com
Sun Jan 6 09:15:08 AEST 1991


In article <1991Jan5.001607.5915 at demott.com> kdq at demott.COM (Kevin D. Quitt) writes:
|     The actual code is:
| 
| 
| const unsigned char *chars   = "some string"
| unsigned char pass[];
| 
|     c   = strchr( chars, toupper( pass[ i ]) ) - chars + 1;
| 
| 
|     gcc would not accept this no matter what I did.

The problem is the "unsigned" type specifier in the declaration for
chars.  Section 3.5.4.1 (Pointer declarators) states that

	For two pointer types to be compatible, both shall be
	identically qualified and both shall be pointers to
	compatible types.

The function "strchr" is defined to return a type "char *"; it is
not compatible with "chars", which is of type "unsigned char *".  Try
removing the "unsigned" specifier from the declaration for "chars", or
explicitly cast the result of the strchr() function to (unsigned char *).


--
	-- Tim Olson
	Advanced Micro Devices
	(tim at amd.com)



More information about the Comp.lang.c mailing list