From: Christoph Spiel <Christoph.Spiel@pa...> - 2006-04-10 11:46:39
Before we discuss seeming problems with cil, let me point out
that Your program is not legal, well-defined C.
> void *a;
> void *b;
> printf("b - a =3D %x\n", b - a);
(1) Addition and subtraction of void* variables is not allowed.
(2) Pointer subtraction is only defined for elements in the same
(3) The difference of two pointers is not "unsigned" as "%x"
translates, but "ptrdiff_t", which is an implementation dependent,
> But I found CIL did not translate void* to char*.
IMHO, there is no reason for it to do so. The Standard says: "A
pointer to void shall have the same representation and alignment
requirements as a pointer to a character type.", but nowhere that
there is an implicit conversion -- and this is what You demand here --
from void* to char*.
> Maybe it should cast void pointers to char pointers
> in arithmetic operations!
Maybe You should cast the pointers before subtracting (and then cast
the difference to a type compatible with Your format specifier)? BTW,
there ain't no such thing as prototype-induced argument coercion with
Dr. Christoph L. Spiel
BMW Forschungs- und Innovationszentrum, EA-41
Lauchstaedter Strasse 5, 80995 Muenchen