Xref: utzoo comp.lang.c:35097 comp.lang.c++:11034 Newsgroups: comp.lang.c,comp.lang.c++ Path: utzoo!censor!geac!alias!rsargent From: rsargent@alias.UUCP (Richard Sargent) Subject: Re: Pointer arithmetic Message-ID: <1991Jan7.173726.1003@alias.uucp> Sender: news@alias.uucp (USENET News) Organization: Alias Research Inc., Toronto ON Canada References: <1991Jan5.001607.5915@demott.com> Date: Mon, 7 Jan 91 17:37:26 GMT In article <1991Jan5.001607.5915@demott.com> kdq@demott.COM (Kevin D. Quitt) writes: > >const unsigned char *chars = "some string" >unsigned char pass[]; > > c = strchr( chars, toupper( pass[ i ]) ) - chars + 1; > > One thing that comes to mind is that a *very* fussy compiler, such as gcc with -pedantic (?) turned on, would complain that the difference could be between strings in two different address spaces. This would result in a meaningless difference. Now, by definition, strchr() returns a pointer to within the string (or NULL, I think). But, the compiler may be ignoring what the standard says the function does, and may just consider it as any function returning a pointer to char. In the event that the character is NOT in the string, a NULL return value will result in a meaningless difference. Checking the return value and only taking the difference when non-NULL may be enough. Or maybe the compiler is just too fussy. Or maybe the compiler has a bug. Or ...