noalias comments to X3J11

Frank Swarbrick swarbric at tramp.Colorado.EDU
Fri Mar 25 10:31:24 AEST 1988


In article <1988Mar23.193330.459 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
:>What does this const thing have to do with the function below getting the
:>suspicious pointer conversion warning?
:>
:> return s ? (int)(s - str) : -1;
:
:You're mixing two separate types of pointer:  s is char *, str is
:const char *.  THOSE ARE NOT THE SAME TYPE.  Evidently the compiler
:is doing the conversion for you, but it's not entirely happy about it.
:In this particular case, adding const to the declaration of s would
:fix it, pretty much.  (The exact rules for this sort of thing may yet
:change again before ANSI C is final.)

I just changed it to
  return s ? s - (char *)str : -1;

and it worked fine.  Thanks for the idea, although you gave it indirectly and
maybe without knowing it...

(Actually I didn't run it, but it compiled without giving the warning.)

Frank Swarbrick (and his cat)
swarbric at tramp.UUCP               swarbric at tramp.Colorado.EDU
...!{ncar|nbires}!boulder!tramp!swarbric
"Remember when you were young.  You shown like the sun..."



More information about the Comp.lang.c mailing list