Pointer arithmetic

Doug Gwyn gwyn at smoke.brl.mil
Wed Jan 9 19:53:34 AEST 1991


In article <1991Jan7.173726.1003 at alias.uucp> rsargent at 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.



More information about the Comp.lang.c mailing list