Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!pacbell.com!ames!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Pointer arithmetic Message-ID: <14794@smoke.brl.mil> Date: 9 Jan 91 08:53:34 GMT References: <1991Jan5.001607.5915@demott.com> <1991Jan7.173726.1003@alias.uucp> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 15 In article <1991Jan7.173726.1003@alias.uucp> rsargent@alias.UUCP (Richard Sargent) writes: >> 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. The actual error in this code is the mixing of pointers to char and to unsigned char. If the compiler still complains after that error is remedied, then it has a problem. Ensuring that pointer arithmetic involves valid operands in this situation is entirely the programmer's responsibility, not the compiler's. Assuming that everything is declared properly and that the chars string contains all possible runtime values of toupper(...), the above pointer arithmetic (with types fixed) is strictly conforming and thus the C implementation should NOT issue a diagnostic.