Macro and struct call-outs from Eiffel 
Author Message
 Macro and struct call-outs from Eiffel

Hi all!

Could someone please explain to me the syntax of external calls to C that
are macros and structs?  (The syntax doesn't appear in ETL that I can find;
it must be an extension.)  For example, in the ISE WEL library, the class
WEL_POINT has a routine  cwin_window_from_point (ptr: POINTER): POINTER that
reads like this:

 cwin_window_from_point (ptr: POINTER): POINTER is
   -- SDK WindowFromPoint
  external
   "C [macro <point.h>] (POINT*): EIF_POINTER"
  end;

Under the wel\library directory, there's a "point.h" file with this macro
definition:

     #define cwin_window_from_point(_ptr_) ((EIF_POINTER) WindowFromPoint
(*(POINT *) _ptr_))

How does the Eiffel call to cwin_window_from_point get translated?

And, while I'm at it, how about this call, from the same WEL_POINT class:

     cwel_point_get_x (ptr: POINTER): INTEGER is
      external
       "C [struct <point.h>] (POINT): EIF_INTEGER"
      alias
       "x"
      end;

with the "POINT" struct defined in Microsoft's "windef.h" file as:

    typedef struct tagPOINT
    {
        LONG  x;
        LONG  y;
    } POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;

(You can guess I'm not too good at C.)  I'd appreciate the help.

---------------------
David Jenkins

"Wer nicht spielt,
nimmt sich viel zu ernst."
-- Ferd. Piatnik



Thu, 22 Aug 2002 03:00:00 GMT  
 Macro and struct call-outs from Eiffel

Quote:
> Could someone please explain to me the syntax of external calls to C that
> are macros and structs?  (The syntax doesn't appear in ETL that I can
find;
> it must be an extension.)

You can find some hints on the following web page:
http://www.eiffel.com/doc/online/eiffel45/papers/externals.html

Quote:
> For example, in the ISE WEL library, the class
> WEL_POINT has a routine  cwin_window_from_point (ptr: POINTER): POINTER
that
> reads like this:

>  cwin_window_from_point (ptr: POINTER): POINTER is
>    -- SDK WindowFromPoint
>   external
>    "C [macro <point.h>] (POINT*): EIF_POINTER"
>   end;

> Under the wel\library directory, there's a "point.h" file with this macro
> definition:

>      #define cwin_window_from_point(_ptr_) ((EIF_POINTER) WindowFromPoint
> (*(POINT *) _ptr_))

> How does the Eiffel call to cwin_window_from_point get translated?

"C [macro <point.h>] (POINT*): EIF_POINTER" means:

- This is some C code
- the C code is a macro (this is true because 'cwin_window_from_point' is
defined
  with #define
- you can find the C definition of 'cwin_window_from_point' in the file
  "point.h"

- 'cwin_window_from_point' has one argument: a pointer on a POINT
- 'cwin_window_from_point' returns an EIF_POINTER (i.e. a void*)

- Show quoted text -

Quote:
> And, while I'm at it, how about this call, from the same WEL_POINT class:

>      cwel_point_get_x (ptr: POINTER): INTEGER is
>       external
>        "C [struct <point.h>] (POINT): EIF_INTEGER"
>       alias
>        "x"
>       end;

> with the "POINT" struct defined in Microsoft's "windef.h" file as:

>     typedef struct tagPOINT
>     {
>         LONG  x;
>         LONG  y;
>     } POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;

This is easier to explain. Here [struct <point.h>] means that
`cwel_point_get_x'
is a member in a structure. The alias "x" tell us that the member is x.

So `i := cwel_point_get_x(ptr)' will be translated into C into "i = ptr.x".

Yours,
Arnaud :O)



Fri, 23 Aug 2002 03:00:00 GMT  
 Macro and struct call-outs from Eiffel
Thanks, Arnaud, this explains a lot!  The link to the paper helps
especially.


Quote:
> > Could someone please explain to me the syntax of external calls to C
that
> > are macros and structs?  (The syntax doesn't appear in ETL that I can
> find;
> > it must be an extension.)

> You can find some hints on the following web page:
> http://www.eiffel.com/doc/online/eiffel45/papers/externals.html

> > For example, in the ISE WEL library, the class
> > WEL_POINT has a routine  cwin_window_from_point (ptr: POINTER): POINTER
> that
> > reads like this:

> >  cwin_window_from_point (ptr: POINTER): POINTER is
> >    -- SDK WindowFromPoint
> >   external
> >    "C [macro <point.h>] (POINT*): EIF_POINTER"
> >   end;

> > Under the wel\library directory, there's a "point.h" file with this
macro
> > definition:

> >      #define cwin_window_from_point(_ptr_) ((EIF_POINTER)
WindowFromPoint
> > (*(POINT *) _ptr_))

> > How does the Eiffel call to cwin_window_from_point get translated?

> "C [macro <point.h>] (POINT*): EIF_POINTER" means:

> - This is some C code
> - the C code is a macro (this is true because 'cwin_window_from_point' is
> defined
>   with #define
> - you can find the C definition of 'cwin_window_from_point' in the file
>   "point.h"

> - 'cwin_window_from_point' has one argument: a pointer on a POINT
> - 'cwin_window_from_point' returns an EIF_POINTER (i.e. a void*)

> > And, while I'm at it, how about this call, from the same WEL_POINT
class:

> >      cwel_point_get_x (ptr: POINTER): INTEGER is
> >       external
> >        "C [struct <point.h>] (POINT): EIF_INTEGER"
> >       alias
> >        "x"
> >       end;

> > with the "POINT" struct defined in Microsoft's "windef.h" file as:

> >     typedef struct tagPOINT
> >     {
> >         LONG  x;
> >         LONG  y;
> >     } POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;

> This is easier to explain. Here [struct <point.h>] means that
> `cwel_point_get_x'
> is a member in a structure. The alias "x" tell us that the member is x.

> So `i := cwel_point_get_x(ptr)' will be translated into C into "i =
ptr.x".

> Yours,
> Arnaud :O)



Fri, 23 Aug 2002 03:00:00 GMT  
 Macro and struct call-outs from Eiffel
Thanks, Arnaud, this explains a lot!  The link to the paper helps
especially.


Quote:
> > Could someone please explain to me the syntax of external calls to C
that
> > are macros and structs?  (The syntax doesn't appear in ETL that I can
> find;
> > it must be an extension.)

> You can find some hints on the following web page:
> http://www.eiffel.com/doc/online/eiffel45/papers/externals.html

> > For example, in the ISE WEL library, the class
> > WEL_POINT has a routine  cwin_window_from_point (ptr: POINTER): POINTER
> that
> > reads like this:

> >  cwin_window_from_point (ptr: POINTER): POINTER is
> >    -- SDK WindowFromPoint
> >   external
> >    "C [macro <point.h>] (POINT*): EIF_POINTER"
> >   end;

> > Under the wel\library directory, there's a "point.h" file with this
macro
> > definition:

> >      #define cwin_window_from_point(_ptr_) ((EIF_POINTER)
WindowFromPoint
> > (*(POINT *) _ptr_))

> > How does the Eiffel call to cwin_window_from_point get translated?

> "C [macro <point.h>] (POINT*): EIF_POINTER" means:

> - This is some C code
> - the C code is a macro (this is true because 'cwin_window_from_point' is
> defined
>   with #define
> - you can find the C definition of 'cwin_window_from_point' in the file
>   "point.h"

> - 'cwin_window_from_point' has one argument: a pointer on a POINT
> - 'cwin_window_from_point' returns an EIF_POINTER (i.e. a void*)

> > And, while I'm at it, how about this call, from the same WEL_POINT
class:

> >      cwel_point_get_x (ptr: POINTER): INTEGER is
> >       external
> >        "C [struct <point.h>] (POINT): EIF_INTEGER"
> >       alias
> >        "x"
> >       end;

> > with the "POINT" struct defined in Microsoft's "windef.h" file as:

> >     typedef struct tagPOINT
> >     {
> >         LONG  x;
> >         LONG  y;
> >     } POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;

> This is easier to explain. Here [struct <point.h>] means that
> `cwel_point_get_x'
> is a member in a structure. The alias "x" tell us that the member is x.

> So `i := cwel_point_get_x(ptr)' will be translated into C into "i =
ptr.x".

> Yours,
> Arnaud :O)



Fri, 23 Aug 2002 03:00:00 GMT  
 Macro and struct call-outs from Eiffel

Quote:

> > Could someone please explain to me the syntax of external calls
> > to C that are macros and structs?  (The syntax doesn't appear in
> > ETL that I can find;
> > it must be an extension.)

> You can find some hints on the following web page:
> http://www.*-*-*.com/

Beware that this is very ISE-specific. Other vendors have different
extensions for this.
IOW if you ever want to move over to a different vendor, you'll have to
rewrite those classes that use these externals. A more portable way is
to write a wrapper function around every structure member and every
macro; I've heard that GOTE will write these for you (available on
www.elj.com, in the Eiffel Archives I think).

Regards,
Joachim
--
This is not an official statement from my employer or from NICE.
Reply-to address changed to discourage unsolicited adverti{*filter*}ts.



Fri, 23 Aug 2002 03:00:00 GMT  
 Macro and struct call-outs from Eiffel

Quote:


> > > Could someone please explain to me the syntax of external calls
> > > to C that are macros and structs?  (The syntax doesn't appear in
> > > ETL that I can find;
> > > it must be an extension.)

> > You can find some hints on the following web page:
> > http://www.eiffel.com/doc/online/eiffel45/papers/externals.html

The original question seem to be for ISE so it's a good resource than
anyway.

Quote:

> Beware that this is very ISE-specific. Other vendors have different
> extensions for this.
> IOW if you ever want to move over to a different vendor, you'll have to
> rewrite those classes that use these externals. A more portable way is
> to write a wrapper function around every structure member and every
> macro;

I just can support that. The only thing you can rely on with the
different Eiffel-compilers is
bla is
        external "C"
        end;

All other won't work directly with another compiler.

The other thing you can rely on is that the base types are quite
simular. But not equal (but for 32-bit systems they are) so you have
EIF_INTEGER, EIF_CHARACTER, EIF_POINTER ..

One of the most important seems to be the EIF_POINTER. All vendors use
this elements very heavily, if you look e.g in ISEs STRING library
you'll find this construct around

$some_feature, This turns in a POINTER which is an EIF_POINTER on the
C-side. AFAIK you are guarentedd that during that call to C this POINTER
is not moved.

My experiences suggest to me that I'm quite safe with this construct as
long as e.g STRING and ARRAYs come into play. But for other stuff you
have to read the docs which are available for the compiler you use.

At the moment I think interfacing SmallEiffel and C is the easiest.
Maybe others have other opinions.

Regards
Friedrich



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. struct macro in nasm

2. ISE Eiffel and encapsulation of C struct with function

3. Why Eiffel is called Eiffel

4. Eiffel components: call for new contributions to the Eiffel Shelf

5. Nested structs and struct.pack

6. struct module + array module = ? ( reading C structs )

7. A macro involving two sub-macros - where the 2nd macro needs results from the first

8. Calling Dll with Pointer of struct

9. Call a Borland Delphi DLL with Structs from LabView

10. Fortran calls a C function that returns a struct

11. Calling C from F90 with (struct *) arguments

12. Encapsulating C bit macros in Eiffel

 

 
Powered by phpBB® Forum Software