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

Tim Tautges tautges at mcs.anl.gov
Sun Sep 7 16:21:09 CDT 2008


I don't think that's quite what I had in mind, based on Jed's question. 
  I see the struct pointers still as proxies for what the handles really 
are down in the implementations; thus, my question about whether we 
really need to define the private structure or just reference it.  The 
only thing I see us doing with these *'s is casting them to what our 
handles really are, in the implementation.  Using private struct *'s 
simply allows us to differentiate between the various types of handles, 
rather than using void* for all of them.  That's what gives us the 
compile time type checking.

- tim

Carl Ollivier-Gooch wrote:
> 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
>>
> 
> 

-- 
================================================================
"You will keep in perfect peace him whose mind is
   steadfast, because he trusts in you."               Isaiah 26:3

              Tim Tautges            Argonne National Laboratory
          (tautges at mcs.anl.gov)      (telecommuting from UW-Madison)
          phone: (608) 263-8485      1500 Engineering Dr.
            fax: (608) 263-4499      Madison, WI 53706




More information about the moab-dev mailing list