[LLVMdev] Variable declarations vs. definitions

Dustin Laurence dllaurence at dslextreme.com
Sat Jan 9 12:57:25 PST 2010


I have yet another question that I believe also stems from deep
ignorance of the linkage types.  How do you declare a global variable
without defining it?  The IR ref. clearly indicates that you can do
this, but it looks like one of the many "too obvious to mention" things
that I struggle with.  It's easy with functions, of course: "declare
@foo" in the header and "define @foo" in the module just like in C.  But
it turns out I have avoided having to learn to do it with variables
until now, when I decided to play with invoke/unwind and see if I could
make a primitive exception mechanism to unwind the stack on my recursive
parser when an error is encountered.

In fact I could avoid it now, but the purpose is to learn as much of the
IR as possible, not use the subset of the language I already understand.

To be clear: remember I'm using Stone Knives here. :-)  I have to figure
out how to make a global variable defined in one translation unit
visible in another (with a header, just like in C).  I could easily make
an exception module with accessor functions, and that is likely the
better software engineering solution, but again my real goal is to learn
as much as possible (I don't need exceptions in the parser, either, but
I want to understand them).

Dustin




More information about the llvm-dev mailing list