Tworzenie dynamicznej tablicy o rozmiarze 0

0

Witajcie,

Pytanie teraz banalne. Czy coś się stanie jak utworzę dynamiczną tablice o rozmiarze 0, a później będę chciał ją usunąć? Jaki będzie miała rozmiar w bajtach, czy będzie to tak jak z pustą klasą, że będzie mieć rozmiar 1? Wiadomo, że jak bym się odwoływał do jej elementów to by było "Access Violation". Napisałem takie coś http://ideone.com/CiQhhy . Chyba ideone by napisał o błędzie wykonania?

4

From 5.3.4/7

When the value of the expression in a direct-new-declarator is zero, the allocation function is called to allocate an array with no elements.

From 3.7.3.1/2

The effect of dereferencing a pointer returned as a request for zero size is undefined.

Also

Even if the size of the space requested [by new] is zero, the request can fail.

2

Ja cię człowieku nie rozumiem. 2 lata na forum i 0 progresu jakiegoś... Nawet w kontekście szukania w dokumentacji...

Size in bytes of the requested memory block.
This is, at least, the size of array type specifier in the new expression when called automatically by such an expression (it can be greater, if the the implementation uses additional storage for array types).
If this argument is zero, the function still returns a distinct non-null pointer on success (although dereferencing this pointer leads to undefined behavior).
size_t is an integral type.

http://www.cplusplus.com/reference/new/operator%20new[]/

1 użytkowników online, w tym zalogowanych: 0, gości: 1