[LLVMdev] Opaque type usage to represent foreign types

Gordon Henriksen gordonhenriksen at mac.com
Sun May 18 11:53:20 PDT 2008


On May 18, 2008, at 14:24, Robert Zeh wrote:

> In my project I have a group of foreign types (C++ classes) that I  
> want to use, but don't want to represent as structs within LLVM.   
> For example, for each field in each C++ class I have a setter and  
> getter function that I'd like to use.  The setters and getters are  
> "extern C" functions to avoid problems with C++'s name mangling.
>
> After going over the documentation it seems like I can do this by  
> creating a unique opaque type for each C++ class to track types  
> during my compilation, and then resolving all of the opaque types to  
> void*

(void in LLVM isn't like void in C. Use i8 instead.)

> Is this a reasonable approach?


Very much so. There's little reason for the extra step of refining the  
opaque types to i8, though. Since you won't be dereferencing the  
pointer directly, you can use either the opaque types you propose or  
i8, whichever is more convenient.

— Gordon





More information about the llvm-dev mailing list