[MOAB-dev] Incomplete types versus void * in ITAPS interfaces

Onkar Sahni osahni at scorec.rpi.edu
Sun Sep 7 15:49:09 CDT 2008


This is possible and even this:

#ifdef __cplusplus
typedef class iBase_VertexHandle_Private *iBase_VertexHandle;
...
typedef class iBase_RegionHandle_Private *iBase_RegionHandle;
typedef class iBase_EntityHandle_Private *iBase_EntityHandle;
#else
typedef struct iBase_VertexHandle_Private *iBase_VertexHandle;
...
typedef struct iBase_RegionHandle_Private *iBase_RegionHandle;
typedef struct iBase_EntityHandle_Private *iBase_EntityHandle;
#endif

#ifdef __cplusplus
  class iBase_EntityHandle_Private {};
  class iBase_VertexHandle_Private : public iBase_EntityHandle_Private {};
  ...
  class iBase_RegionHandle_Private : public iBase_EntityHandle_Private {};
#endif

And this will support overloading, inheritance....

example:
getVertexCoords(iBase_VertexHandle,....);
getTypeOfEnt(iBase_EntityHandle,...);
print_EntInfo(iBase_VertexHandle,...); // C++
print_EntInfo(iBase_RegionHandle,...); // C++

Does this change fit into SIDL/Babel paradigm?

- Onkar

> Tim Tautges wrote:
>> Interesting question, which I'm forwarding to the rest of the ITAPS
>> interface group.  One question, would that require you to actually
>> define the private structure, or just reference it?  The extra type
>> checking would be very useful (and would be useful inside MOAB as
>> well...).
>
> My first reaction was that I never would have thought that this would be
> compilable.  Jed obviously knows something about C syntax that I don't,
> because it does seem to work, at least in terms of compiling and linking
> (see attached files).  I defined two different structs, one in C, one in
> C++, and both linked fine (as in: both test2.o and test3.o link with
> test.o with no complaints).  Mind you, I never tried to do anything
> beyond what's in these files, so it's possible that the compiler
> optimized away anything that might have been a problem.
>
>  From the implementation side, if we made this change, we'd all have to
> have an explicit iBase_EntityHandle_Private (plus half a dozen or so
> others), but in exchange we get type checking and may be able to avoid a
> bunch of casts (that's probably implementation dependent...
>
> Carl
>
>> Jed Brown wrote:
>>> Sorry if this is the wrong list for this, but why are all the opaque
>>> handles typedef'd to void * instead of incomplete types.  That is, why
>>> not something like
>>>
>>>   typedef struct iBase_EntityHandle_Private *iBase_EntityHandle;
>>>
>>> in order to get some extra type checking?  Correct existing code should
>>> not see any difference.  With this change, a possible logic error
>>> (using
>>> EntitySetHandle for an EntitySet) in the VisIt plugin would be caught
>>> by
>>> the compiler.
>>>
>>> Jed
>>
>
>
> --
> ------------------------------------------------------------------------
> Dr. Carl Ollivier-Gooch, P.Eng.                   Voice: +1-604-822-1854
> Associate Professor                                 Fax: +1-604-822-2403
> Department of Mechanical Engineering             email: cfog at mech.ubc.ca
> University of British Columbia              http://www.mech.ubc.ca/~cfog
> Vancouver, BC  V6T 1Z4                  http://tetra.mech.ubc.ca/ANSLab/
> ------------------------------------------------------------------------
>





More information about the moab-dev mailing list