Xref: utzoo comp.lang.c:35040 comp.lang.c++:10993 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!srhqla!demott!kdq From: kdq@demott.com (Kevin D. Quitt) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Pointer arithmetic Message-ID: <1991Jan5.001607.5915@demott.com> Date: 5 Jan 91 00:16:07 GMT Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 35 I originally posted to comp.lang.c++ (don't know how it got there): > What about the subtraction of pointers to get a constant? I discovered >that gcc does not allow: > > int = strchr( string, char ) - &string; > >to determine the position of char within string. Is there a (good) reason >for disallowing this? BTW, Microsoft C *does* accept this. I rapidly received two responses indicating that the & was the problem. (Nobody picked on using int and char as variables :-) The & was "artistic" in my example. Microsoft C does allow &string, but provides a warning that the ampersand is ignored. 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. -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last