• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: g++ 4.0.2 linking problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ 4.0.2 linking problem


  • Subject: Re: g++ 4.0.2 linking problem
  • From: "Edward K. Chew" <email@hidden>
  • Date: Thu, 21 Dec 2006 22:40:05 -0500

On 21-Dec-06, at 8:49 PM, B.J. Buchalter wrote:

On 12/21/06 8:36 PM, "Edward K. Chew" <email@hidden> wrote:

There must be a simple explanation for this, but I am sadly too sleep-
deprived to see it. Here's the code:



struct Foo { static const int kMaxBar = 100; int bar; int bestBar() const; };

I think you need a

static const int Foo::kMaxBar = 100;

outside the struct/class.

Well, I haven't got Stroustrup in front of me at the moment, but I was under the impression it is okay to initialize static constants within a class in modern C++, provided they are integer types. At any rate, my real code uses the constant elsewhere within the class declaration, so I need it defined early on.


My best guess is that the compiler/linker is somehow getting mixed up about int, const int, and constant methods. Here are a number of workarounds I have found which seem to placate the linker:

int bestBar() /* no const */ { return bar < kMaxBar ? bar : kMaxBar; }
int bestBar() const { return bar < kMaxBar ? (int)bar : kMaxBar; }
int bestBar() const { return bar < kMaxBar ? bar : (int)kMaxBar; }

It seems odd that I would have to do this, and I am tempted to file a bug, but I thought I'd check here first to see if I am breaking any subtle C++ rules. (It wouldn't be the first time...)

-Ted

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: g++ 4.0.2 linking problem
      • From: David Fang <email@hidden>
References: 
 >Re: g++ 4.0.2 linking problem (From: "B.J. Buchalter" <email@hidden>)

  • Prev by Date: No Build options for Rez phase - Xcode2.4
  • Next by Date: Re: No Build options for Rez phase - Xcode2.4
  • Previous by thread: Re: g++ 4.0.2 linking problem
  • Next by thread: Re: g++ 4.0.2 linking problem
  • Index(es):
    • Date
    • Thread