Project

General

Profile

Bug #55

Bug #53: MSVC10 compilation

MSVC10 - static member fields

Added by Anna Maria Bigatti over 12 years ago. Updated about 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Portability
Target version:
Start date:
07 Dec 2011
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

In many .C files we have
const int MantExp::ourDefaultSigFig; // pointless but necessary

but Visual Studio complains about it. Who's right?

History

#1 Updated by Anna Maria Bigatti over 12 years ago

  • Category set to Portability

#2 Updated by Anna Maria Bigatti over 12 years ago

  • Subject changed from MSVC10 compilation - static member fields to MSVC10 - static member fields

#3 Updated by John Abbott about 12 years ago

Reported under #58 by mistake.

#4 Updated by Anna Maria Bigatti about 12 years ago

  • Assignee set to John Abbott
  • Target version set to CoCoA-5.0.2
  • % Done changed from 30 to 40

In some cases we can move the initialization in the .C file
(see #58 ""Moved initializer for const static data member from decimal.H to decimal.C.
Allows compilation with MSVC, and give better decoupling (no need to recompile
many files if we change the value).")

In other cases (e.g. DivMask) the static variable is needed in the .H file to define
the type std::bitset<ourMaskWidth> mask_t

I commented out the (empty) declaration in DivMask.C and it compiled with no errors or warnings under MacOSX and Linux (gcc).... but it doesn't link under MacOSX!
It does link under Linux: newer compiler.
So: who is right?

#5 Updated by Giovanni Lagorio about 12 years ago

  • % Done changed from 40 to 50

It doesn't seem a problem in VC10 SP1 (tried on a toy example).
From my understanding of the standard, it shouldn't give an error in such cases.
To me, it seems that such definition might be useless but not wrong.

#6 Updated by John Abbott about 12 years ago

I looked on internet, but did not find an answer which I feel is truly definitive. If the initializer is a constant integer value and the address of the const static member is never needed then it seems that it might be OK not to give a "definition" of the member (but some people report that it is "undefined behaviour" in certain versions of the C++ standard). Regardless, it must be a VC10 bug to give an error; perhaps the solution is to install SP1 (is this free, or must one pay for it?)

#7 Updated by John Abbott about 12 years ago

  • Status changed from New to Closed
  • % Done changed from 50 to 100

Exercising the option not to define static data members if their addrs are not needed, I have removed all such defns, thereby circumventing the MSVC 2010 bug. This did require a minor modification to DivMask.C which used to call std::min (which expects references, so requires addrs) but now calls an ad hoc private fn called min.

Also available in: Atom PDF