Home > Net >  How can a array provide storage?
How can a array provide storage?

Time:11-11

In C draft The first paragraph is talking about situations where an array provides storage:

If a complete object is created ([expr.new]) in storage associated with another object e of type “array of N unsigned char” or of type “array of N std​::​byte” ([cstddef.syn]), that array provides storage for the created object if:...

In these cases array is refering to an unsigned char C[1] or to std::array? If is the first case, I can, for example, create an object at the same memory addres of a existing array C and then this array C will provide storage, but only if its type is the cited above? What would happen if it was just a char array and not a unsigned char array?

CodePudding user response:

In these cases array is refering to an unsigned char C[1] or to std::array?

"Array" refers to arrays such as T[N].

"Array" doesn't refer to std::array. std::array isn't an array, but rather it is a class template. std::array may contain an array as a member.

array (with formatting that signifies code) refers to std::array.

What would happen if it was just a char array and not a unsigned char array?

Strict interpretation would be that no other type could "provide storage" for another object unless that is specified by another rule.

A loose interpretation would be that other types may provide storage, and the conditions that follow the quoted rule do not apply to them.

  • Related