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

Carl Ollivier-Gooch cfog at mech.ubc.ca
Sun Sep 7 15:14:43 CDT 2008


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/
------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 120 bytes
Desc: not available
URL: <https://lists.mcs.anl.gov/mailman/private/moab-dev/attachments/20080907/0ee8d5ed/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.c
Type: text/x-csrc
Size: 77 bytes
Desc: not available
URL: <https://lists.mcs.anl.gov/mailman/private/moab-dev/attachments/20080907/0ee8d5ed/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test3.cc
Type: text/x-c++src
Size: 112 bytes
Desc: not available
URL: <https://lists.mcs.anl.gov/mailman/private/moab-dev/attachments/20080907/0ee8d5ed/attachment.cc>


More information about the moab-dev mailing list