xmllmx
xmllmx

Reputation: 42379

Does the C++11 standard guarantee the memory layout of initializer_list's objects are cross-compiler compatible?

vc++ implements the std::initializer_list as follows:

template<class T>
class initializer_list
{
public:
    // ...

private:
    const value_type* _first;
    const value_type* _last;
};

However, clang 3.4 implements the std::initializer_list in another way:

template<class T>
class initializer_list {
    const T* _p;
    size_t _size;
    // ...
};

Obviously, the two definitions are not binary-compatible with each other.

Why does the C++ standard not explicitly define the memory layout of std::initializer_list for compatibility?

Upvotes: 2

Views: 256

Answers (1)

Mark B
Mark B

Reputation: 96291

The C++ standard specifically does not impose implementation details to allow an implementation to provide the functionality in a manner most efficient for the hardware being targeted. The language does not make you pay for functionality you don't need and generally allows for the compiler to make broad decisions to optimize the code for size/performance on given hardware. Specifying a specific ABI could force undue burden on compilers and compiled C++ programs.

Upvotes: 4

Related Questions