[LLVMdev] struct and class under VC7.1

Chris Lattner sabre at nondot.org
Thu Sep 23 08:39:11 PDT 2004


On Thu, 23 Sep 2004, Reid Spencer wrote:

> I have just committed a change to Value.h that changes the Value class
> from using a "struct" declaration to a "class" declaration. I'm not sure
> why VC7.1 would generate different symbols for class vs. struct. I'm
> pretty certain that's a violation of the ABI.

Yes, I'm pretty certain that this is a violation of standard C++.

> In any event, we should be consistent. The Value class is declared
> "class Value" in numerous places in LLVM and it really should be "class"
> not "struct" (most of its data members are private).  There may now be
> some places in LLVM that declare Value as "struct Value".

If we are going to do this change, I think it makes sense to standardize
on "class" and just use if everywhere.  Until now, we've basically used
whatever has been convenient.

> If you run into these, please provide patches so we can get this
> consistent across LLVM.

Please also submit a patch to the CodingStandards.html file so that future
contributors know about this rule too.

Thanks!

-Chris

> On Thu, 2004-09-23 at 07:37, Paolo Invernizzi wrote:
> > On Sep 23, 2004, at 4:08 PM, Jeff Cohen wrote:
> >
> > > MSVC++ is picky about this.  It considers classes and structs to be
> > > different types so you have to be consistent.  If you forward declared
> > > a
> > > struct as a class within the same compilation unit, it would complain
> > > about that too.  It's not just linking.
> >
> > You are right...
> >
> > BTW, I've just fixed that problem in my checkout and, among others
> > terrible hacks, here I am:
> >
> > :\home\arathorn\sandbox\llvm>HowToUseJIT.exe
> > We just constructed this LLVM module:
> >
> >
> > implementation   ; Functions:
> >
> > int %add1(int %AnArg) {
> > EntryBlock:
> >          %addresult = add int 1, %AnArg          ; <int> [#uses=1]
> >          ret int %addresult
> > }
> >
> > int %foo() {
> > EntryBlock:
> >          %add1 = call int %add1( int 10 )                ; <int>
> > [#uses=1]
> >          ret int %add1
> > }
> >
> >
> > Running foo: Result: 11
> >
> > D:\home\arathorn\sandbox\llvm>
> >
> > Yabba! Yabba! Yabba! ;-)
> >
> > ---
> > Paolo Invernizzi
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list