noalias comments to X3J11

Henry Spencer henry at utzoo.uucp
Thu Mar 24 05:33:30 AEST 1988


>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.)
-- 
"Noalias must go.  This is           |  Henry Spencer @ U of Toronto Zoology
non-negotiable."  --DMR              | {allegra,ihnp4,decvax,utai}!utzoo!henry



More information about the Comp.lang.c mailing list