Re: [eigen] proposal to use static const integer class members instead of enum values |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
On Sat, 13 Dec 2014, Benoit Jacob wrote:
2014-12-13 11:14 GMT-08:00 Marc Glisse <marc.glisse@xxxxxxxx>:On Sat, 13 Dec 2014, Benoit Jacob wrote: 2014-12-13 10:47 GMT-08:00 Marc Glisse <marc.glisse@xxxxxxxx>:On Sat, 13 Dec 2014, Benoit Jacob wrote: Eigen does this for storing integer constants on a class:class C { enum { SomeConstant = SomeValue }; }; Most other C++ code (including libstdc++ and libc++) do this instead: class C { static const some_integer_type SomeConstant = SomeValue; };You are missing the extra: const some_integer_type C::SomeConstant; Otherwise, passing this value by reference may yield undefined references, especially at -O0.That would be the case for a static-storage non-constant integer, but not for a static-storage constant integer, see: http://stackoverflow.com/questions/9219898/why-can-you- initialize-a-static-const-variable-inline-but-not-a-plain-static-cYou misread my message. I am not complaining about the initialization but about the lack of definition. $ cat r.cc struct A { static const int i = 42; }; void f(int const&) { } int main() { f(A::i); } $ g++ r.cc /tmp/ccqlsWDU.o: In function `main': r.cc:(.text+0xf): undefined reference to `A::i' collect2: error: ld returned 1 exit statusEigen is all headers, so I'm only proposing making this change in header files!
I don't see how that's relevant. You can rename A as Matrix and i as dimension if you want, and move it to a header, it will not change anything.
Given that I don't see a problem with static const int it = 42; ?
Sorry, I don't think I can make my argument clearer than the above example, or maybe:
https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definitionHopefully someone else on the list can tell us in what way we are misunderstanding each other.
-- Marc Glisse
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |