Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gforth] libcc.fs bitfield structure as a parameter

10 views
Skip to first unread message

pliz

unread,
Dec 14, 2009, 6:33:04 PM12/14/09
to
Hi gforthers,

I appreciate help in the following issue. I am trying to make bindings
to functions in libcgraph of the latest graphviz release and having
trouble with a function.

Here is the relevant part from cgraph.h:
typedef struct Agdesc_s Agdesc_t; /* graph descriptor */
struct Agdesc_s { /* graph descriptor */
unsigned directed:1; /* if edges are asymmetric */
unsigned strict:1; /* if multi-edges forbidden */
unsigned no_loop:1; /* if no loops */
unsigned maingraph:1; /* if this is the top level graph */
unsigned flatlock:1; /* if sets are flattened into lists in cdt */
unsigned no_write:1; /* if a temporary subgraph */
unsigned has_attrs:1; /* if string attr tables should be
initialized */
unsigned has_cmpnd:1; /* if may contain collapsed nodes */
};
extern Agraph_t *agopen(char *name, Agdesc_t desc, Agdisc_t * disc);

As you see second parameter to agopen is a byte (if I get it right).
So in gforth I do the following:
s" cgraph" add-lib ok
\c #include <graphviz/cgraph.h> ok
c-function agopen agopen a n a -- a ok
s" test" c-string 8 0 agopen

which results in:

error: incompatible type for argument 2 of ‘agopen’
:4: libtool compile failed
s" test" c-string 8 0 >>>agopen<<<
Backtrace:
$B7B0FB14 throw
$B7B320A0 c(abort")
$B7B324B0 compile-wrapper-function

I have also tried argument a with the same result.
How to compile the binding to agopen?

Any ideas appreciated.

--
Sergey

Anton Ertl

unread,
Dec 15, 2009, 7:51:04 AM12/15/09
to
pliz <s.m....@gmail.com> writes:
>Hi gforthers,
>
>I appreciate help in the following issue. I am trying to make bindings
>to functions in libcgraph of the latest graphviz release and having
>trouble with a function.
>
>Here is the relevant part from cgraph.h:
>typedef struct Agdesc_s Agdesc_t; /* graph descriptor */
>struct Agdesc_s { /* graph descriptor */
> unsigned directed:1; /* if edges are asymmetric */
> unsigned strict:1; /* if multi-edges forbidden */
> unsigned no_loop:1; /* if no loops */
> unsigned maingraph:1; /* if this is the top level graph */
> unsigned flatlock:1; /* if sets are flattened into lists in cdt */
> unsigned no_write:1; /* if a temporary subgraph */
> unsigned has_attrs:1; /* if string attr tables should be
>initialized */
> unsigned has_cmpnd:1; /* if may contain collapsed nodes */
>};
>extern Agraph_t *agopen(char *name, Agdesc_t desc, Agdisc_t * disc);
>
>As you see second parameter to agopen is a byte (if I get it right).

The second argument may fit into a byte, but as far as C is concerned,
it's a struct, and struct types are incompatible with integer types.

>So in gforth I do the following:
>s" cgraph" add-lib ok
>\c #include <graphviz/cgraph.h> ok
>c-function agopen agopen a n a -- a ok
>s" test" c-string 8 0 agopen
>
>which results in:
>

>error: incompatible type for argument 2 of =91agopen=92

There are various workarounds for that. One would be to introduce a
union between Agdesc_t and an integer type, and then have a helper
macro along these lines (untested):

\c union Agdesc_u { Agdesc_t s; Cell x; };
\c #define agopen1(name, desc, disc) \
\c ({union Agdesc_u _desc; _desc.x=(desc); agopen((name), _desc.s, (disc));})
c-function agopen agopen1 a n a -- a

or alternatively you could pass the address of the desc parameter at
the Forth level, and the helper macro would dereference the pointer.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2009: http://www.euroforth.org/ef09/

pliz

unread,
Dec 15, 2009, 12:31:43 PM12/15/09
to
This works. Thanks!


On Dec 15, 5:51 am, an...@mips.complang.tuwien.ac.at (Anton Ertl)
wrote:

0 new messages