Another question on C inline usage

7 Messages Forum Options Options
Permalink
Chris Saunders-4
Another question on C inline usage
Reply Threaded More
Print post
Permalink
I'm trying to write an interface to a C struct.  I'm not at all sure that I
should be using this approach and would like some advice on weather I should
use this approach.  I am also getting an error when C compiling and can't
see the source of the error (my C is limited).  Here is the code I wrote:

 

 

                quot (a_item: POINTER): INTEGER

                                external

                                                "C inline use <stdlib.h>"

                                alias

                                                "[

                                                {

                                                                struct
div_t* itm =  $a_item;

                                                                return
(int)a_item->quot;

                                                }

                                                ]"

                                end

 

                set_quot (a_item: POINTER; v: INTEGER)

                                external

                                                "C inline use <stdlib.h>"

                                alias

                                                "[

                                                {

                                                                struct
div_t* itm = $a_item;

 
(int)a_item->quot = $v;

                                                }

                                                ]"

                                end

 

The compiler error is:

 

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(43) :
error C2065: 'a_item' : undeclared identifier

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(43) :
error C2223: left of '->quot' must point to struct/union

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(54) :
error C2065: 'a_item' : undeclared identifier

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(54) :
error C2223: left of '->quot' must point to struct/union

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\Bin\amd64\cl.EXE"' : return code '0x2'

Stop.

 

Can anyone assist?

 

Regards

Chris Saunders



[Non-text portions of this message have been removed]


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Emmanuel Stapf [ES]
Re: Another question on C inline usage
Reply Threaded More
Print post
Permalink
> c:\users\saunders\documents\eiffel 6.2 user
> files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(43)
> :
> error C2065: 'a_item' : undeclared identifier

It is because you forgot to do $a_item in the alias clause of both externals.

Regards,
Manu

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Eric Bezault
Re: Another question on C inline usage
Reply Threaded More
Print post
Permalink
Chris Saunders wrote:

>   quot (a_item: POINTER): INTEGER
>      external
>         "C inline use <stdlib.h>"
>      alias
>         "[
>      {
>
>          struct div_t* itm =  $a_item;
>          return (int)a_item->quot;
>      }
>         ]"
>      end
>
> Can anyone assist?

I guess it should be:

    return (int)(itm->quot);

using `itm' and not `a_item'.

--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Chris Saunders-4
RE: Another question on C inline usage
Reply Threaded More
Print post
Permalink
First thanks to Manu and Eric Bezault for your help.  I should have seen the
obvious code error but sometimes the obvious is something you just can't
seem to see.  I altered the code to this:

 

 

                quot (a_item: POINTER): INTEGER

                                external

                                                "C inline use <stdlib.h>"

                                alias

                                                "[

                                                {

                                                                struct
div_t* itm =  $a_item;

                                                                return
(int)(itm->quot);

                                                }

                                                ]"

                                end

 

                set_quot (a_item: POINTER; v: INTEGER)

                                external

                                                "C inline use <stdlib.h>"

                                alias

                                                "[

                                                {

                                                                struct
div_t* itm = $a_item;

 
(int)(itm->quot) = $v;

                                                }

                                                ]"

                                end

 

I now get the error:

 

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(43) :
error C2037: left of 'quot' specifies undefined struct/union 'div_t'

c:\users\saunders\documents\eiffel 6.2 user
files\projects\mandolin3\eifgens\mandolin3_project\w_code\c4\di2005.c(54) :
error C2037: left of 'quot' specifies undefined struct/union 'div_t'

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\Bin\amd64\cl.EXE"' : return code '0x2'

Stop.

 

div_t is declared in stdlib.h so I don't see why this should appear to be
undefined to the C compiler.  I would also like to ask Eric why the need for
the brackets around (itm->quot)?  Here is the declaration of div_t from my
version of stdlib.h:

 

 

typedef struct _div_t {

        int quot;

        int rem;

} div_t;

 

Regards

Chris Saunders

 

From: eiffel_software@...
[mailto:eiffel_software@...] On Behalf Of Eric Bezault
Sent: Saturday, July 05, 2008 3:17 AM
To: eiffel_software@...
Subject: Re: [eiffel_software] Another question on C inline usage

 

Chris Saunders wrote:

> quot (a_item: POINTER): INTEGER
> external
> "C inline use <stdlib.h>"
> alias
> "[
> {
>
> struct div_t* itm = $a_item;
> return (int)a_item->quot;
> }
> ]"
> end
>
> Can anyone assist?

I guess it should be:

return (int)(itm->quot);

using `itm' and not `a_item'.

--
Eric Bezault
mailto:ericb@... <mailto:ericb%40gobosoft.com>
http://www.gobosoft.com

 



[Non-text portions of this message have been removed]


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Chris Saunders-4
RE: Another question on C inline usage
Reply Threaded More
Print post
Permalink
I managed to correct my code so that it compiles fine - I had to change
struct div_t* itm =  $a_item; to  div_t* itm =  $a_item;.  Still one
question though - neither of you commented on whether I should use this
approach on defining an interface to a C struct or if I should use the older
way of doing this from Eiffel?

 

Regards

Chris Saunders



[Non-text portions of this message have been removed]


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Eric Bezault
Re: Another question on C inline usage
Reply Threaded More
Print post
Permalink
Chris Saunders wrote:
>  I would also like to ask Eric why the need for
> the brackets around (itm->quot)?

It's for clarity for the human readers (who are more
error-prone than compilers to remember what the
precedence level between operators are).

--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Emmanuel Stapf [ES]
RE: Another question on C inline usage
Reply Threaded More
Print post
Permalink
> question though - neither of you commented on whether I should use this
> approach on defining an interface to a C struct or if I should use the
> old way of doing this from Eiffel?

I would only use the new way. It is actually much simpler overall and much more
powerful.

Regards,
Manu


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/