[m-dev.] bugs?

Julien Fischer juliensf at students.cs.mu.OZ.AU
Tue Feb 3 16:06:55 AEDT 2004


On Tue, 3 Feb 2004, Peter Schachte wrote:
...
> Secondly, when I try to compile that code, I get several warnings from
> the C compiler about missing int<->pointer casts:
>
>     mudla% mmake pointer_example.o 14:57
>     mmc --compile-to-c --grade asm_fast.gc pointer_example >
>     pointer_example.err 2>&1
>     mgnuc --grade asm_fast.gc -- -c pointer_example.c -o pointer_example.o
>     pointer_example.m: In function `pointer_example_module0':
>     pointer_example.m:27: warning: assignment makes integer from pointer
>     without a cast
>     pointer_example.m: In function `pointer_example_module1':
>     pointer_example.m:31: warning: passing arg 2 of `perform_calculation'
>     makes pointer from integer without a cast
>     pointer_example.m:31: warning: assignment makes integer from pointer
>     without a cast
>     rm pointer_example.c
>
> Any idea what the problem could be, or how to fix it?  I'm using gcc
> 3.3.2 (Debian).  I get similar messages for any foreign interface code
> I compile.
>

I believe the problem comes about because the type c_pointer is
a value of type MR_Word and that MR_Word is (eventually) a typedef
for int ... (others can probably provide a better explanation).

One way to fix it (or at least shut the compiler up) would be to
add casts (see below).  You might also consider using the
new foreign language interface instead and defining
complicated_c_structure as a foreign type.  That would probably eliminate
the need for most of the casts.

Julien.


:- module pointer_example.

:- interface.

:- type complicated_c_structure.

% Initialise the abstract C structure that we pass around in Mercury.
:- pred initialise_complicated_structure(complicated_c_structure::uo) is det.

% Perform a calculation on the C structure.
:- pred do_calculation(int::in, complicated_c_structure::di,
        complicated_c_structure::uo) is det.

:- implementation.

% Our C structure is implemented as a c_pointer.
:- type complicated_c_structure --->
        complicated_c_structure(c_pointer).

:- pragma c_header_code("
        extern struct foo *init_struct(void);
        extern struct foo *perform_calculation(int, struct foo *);
").

:- pragma c_code(initialise_complicated_structure(Structure::uo),
        [may_call_mercury],
        "Structure = (MR_Word) init_struct();").

:- pragma c_code(do_calculation(Value::in, Structure0::di, Structure::uo),
        [may_call_mercury],
        "Structure = (MR_Word) perform_calculation(Value,
		(struct foo *) Structure0);").

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list