Re: gec: Is it possible to specify a signature for a external C call?
Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> Mon, 12 Nov 2007 06:35:35 +0100
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Message-ID | <[email protected]> |
Berend de Boer wrote:
> Hi All,
>
> Just trying to gec working with eposix, and stumbled upon a situation
> that baffled me completely for a while.
>
> I have this Eiffel function:
>
> posix_difftime (time_end, time_start: INTEGER): DOUBLE is
> external "C"
> end
>
> The C function behind this has this signature:
>
> EIF_DOUBLE posix_difftime(EIF_INTEGER time1, EIF_INTEGER time0);
>
>
> Gobo calls this fine, however, it does not create a signature for this
> posix_difftime.
>
> It seems C creates a default signature in this case, something like
>
> int posix_difftime(int time1, int time0);
>
>
> As you can see, this function returns an int instead of a double. So all
> my calls to C functions that return a double are completely wrong.
>
>
> I think Gobo should create default signatures for external functions
> just matching the Eiffel code signature. That would fix the problem.
>
> I could also specify a signature myself, but how to do that? Does gec
> already support that?
You can write:
posix_difftime (time_end, time_start: INTEGER): DOUBLE is
external
"C signature (EIF_INTEGER, EIF_INTEGER): EIF_DOUBLE"
end
But I don't think that it will help you because this will not
generate a prototype for 'posix_difftime', just some type casts.
When you wrote 'posix_difftime', you should have written a prototype
for it in some header file as well. So what you have to do is:
posix_difftime (time_end, time_start: INTEGER): DOUBLE is
external
"C use %"some_header_file.h%""
end
where 'some_header_file.h' is your header file.
--
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com