develooper Front page | perl.perl6.internals | Postings from December 2001

pointer warnings in interpreter.c

Thread Next
From:
Nicholas Clark
Date:
December 31, 2001 15:13
Subject:
pointer warnings in interpreter.c
Message ID:
20011231231012.A2250@Bagpuss.unfortu.net
I'm attempting to make a start on annihilating the warnings picked up by all
the new gcc stricture, but it seems that there are actually some existing
compiler warnings about pointer confusion.

Aside from the hundreds in core_ops.c and core_ops_prederef.c (which may be
the same cause) there is an obvious snafu in interpreter.c. Although it's
obvious what the error is, it's not obvious to me what the correction should
be.

gcc reports:

nick@Bagpuss [parrot-Wall]$ cc -DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64     -I./include  -o interpreter.o -c interpreter.c
interpreter.c: In function `runops_prederef':
interpreter.c:316: warning: passing arg 1 of pointer to function from incompatible pointer type
interpreter.c:316: warning: passing arg 2 of pointer to function from incompatible pointer type

which is this:
              ((op_func_prederef_t)*pc_prederef) (pc_prederef, interpreter);

where the parameters to the function are

struct Parrot_Interp *interpreter
void ** pc_prederef

and op_func_prederef_t is

include/parrot/op.h:typedef void **(*op_func_prederef_t)(struct Parrot_Interp *, void **);

ie the types are transposed.

But is the correct correction to swap the parameters

((op_func_prederef_t)*pc_prederef) (interpreter, pc_prederef);

or to change the typedef?

And why do we need the cast? I think it's undefined behaviour (we're casting
pointer to data to pointer to function). Not that very many platforms get
upset about that sort of thing. IIRC the only thing that turned up on p5p
disliking casting function pointers to and from data pointers was some sort
of obsolescent Cray.

Nicholas Clark

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About