STL Static-Const Member Definitions

How does the following work?

#include <limits>

int main()
{
  const int* const foo = &std::numeric_limits<int> ::digits;
}

I got the impression that in order to accept the member address static const- ant, we had to physically define it in some translation unit to please the linker. However, looking at the pre-processed code for this TU, I could not find the external definition for the member digits(or any other relevant members).

I tested this on two compilers (VC ++ 10 and g ++ 4.2.4) and got the same results from both (i.e. it works). Is the linker automatically linked magically to the object file where this material is defined, or am I missing something obvious here?

+3
source share
1 answer

Well, what makes you think it is undefined? The fact that your attempt to complete the address automatically indicates that it is defined somewhere. Of course, there is no need to constantly be in your transaction block, so viewing the output of the preprocessor does not make much sense.

+2
source

Source: https://habr.com/ru/post/1742375/


All Articles