ppl_Polyhedron_t is an opaque pointer:
http://en.wikipedia.org/wiki/Opaque_pointer

(often also called an incomplete type. heavily used pattern in the Julia C
source, by the way)

In the example you gave, the "struct" is allocated here:

ppl_Polyhedron_t ppl_ph;
>

In the call to ppl_new_C_Polyhedron_recycle_Constraint_System(&ppl_ph,
 ppl_cs) the `&` means to pass the address of that variable (so,
effectively void**). ppl_new_... does the actual allocation, and places the
address of the internal data structure into the pointer (if you look
further down in that example there is call to
`ppl_delete_polyhedron(ppl_ph)`).

There is a discussion of how to pass pre-allocated pointers in the C
section of the manual:
http://docs.julialang.org/en/release-0.3/manual/calling-c-and-fortran-code/#passing-pointers-for-modifying-inputs

Hope that helps.


On Tue, Feb 17, 2015 at 8:40 PM, Zenna Tavares <[email protected]>
wrote:

> I'm trying to wrap the Parma Polyhedron Library in Julia.
>
> The library itself is written in C++, I am trying to wrap the C API.
>
> Consider a snippet of an C example which uses the C API
>
> static int
> solve_with_generators(ppl_Constraint_System_t ppl_cs,
>                       ppl_const_Linear_Expression_t ppl_objective_le,
>                       ppl_Coefficient_t optimum_n,
>                       ppl_Coefficient_t optimum_d,
>                       ppl_Generator_t point) {
>   ppl_Polyhedron_t ppl_ph;
>   ...
>   /* Create the polyhedron (recycling the data structures of ppl_cs). */
>   ppl_new_C_Polyhedron_recycle_Constraint_System(&ppl_ph, ppl_cs);
>
>
>
> To illustrate my problem, consider the call to*
> ppl_new_C_Polyhedron_recycle_Constraint_System* which creates a
> constraint system, and has signature:
>
> ppl_new_C_Polyhedron_recycle_Constraint_System(ppl_Polyhedron_t* pph,
> ppl_Constraint_System_t cs)
>
>
>
> *ppl_Polyhedron_*t is typedef generated using macros, but effectively it
> is defined by
>
> typedef struct ppl_Polyhedron_tag* ppl_Polyhedron_t;
>
> I can't find anywhere in the source where these structs are defined, but
> presumably they must (my C is very rusty).  In any case, the problem is
> that from Julia I don't have access to these typedefs.  If I want to ccall
> *ppl_new_C_Polyhedron_recycle_Constraint_System*, what can I use as the
> first and second arguments?  My (currently very naive) intuition is that I
> need C functions which return values of the type *ppl_Polyhedron_t* for
> instance, but it seems this API does not follow that pattern.  Is this
> correct? Will I need to do something like write another C API which just
> returns pointers? Or is there a simpler solution?
>
> Thanks
>

Reply via email to