[LLVMdev] Variable declarations vs. definitions

Eli Friedman eli.friedman at gmail.com
Sat Jan 9 13:11:49 PST 2010


On Sat, Jan 9, 2010 at 12:57 PM, Dustin Laurence
<dllaurence at dslextreme.com> wrote:
> 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.

The syntax isn't entirely obvious... usually, when you're wondering
how to write something in IR, the easiest thing to so is write the
equivalent C code, then use http://llvm.org/demo/index.cgi to see what
it looks like in iR.  In this case, try plugging the following snippet
in:

extern int x;
int *y = &x;

-Eli




More information about the llvm-dev mailing list