3

について読んでrealloc()いるときに、無視するのではなく明確にする必要があるいくつかの疑問に遭遇しました.あなたの答えが非常に求められています.明確にするために番号を付けたリストに入れました.この質問の長さは気にしないでください.

1)を使用してrealloc()いるときに、その内容を含むメモリ ブロックが新しい場所に移動された場合、その上で free() を呼び出したかのように、元のアドレスの割り当てが解除されますcplusplusreferenceか?reallocこのような場合、元のメモリ ブロックの割り当てが解除されることを示唆していますが、確認が必要です。

->C90 (C++98)C99/C11 (C++11) Otherwise, if size is zero, the memory previously allocated at ptr is deallocated as if a call to free was made, and a null pointer is returned.

->If the function fails to allocate the requested block of memory, a null pointer is returned, and the memory block pointed to by argument ptr is not deallocated (it is still valid, and with its contents unchanged).

2) ここに疑問を提起する別の行があります: "If the new size is larger, the value of the newly allocated portion is indeterminate.".Well,here is what I want to know

i)その新しく割り当てられた部分に書き込むことはできますか?

ii)新たに割り当てられた部分はガベージ値で満たされていますか?

3)そして最後に、配列オブジェクトを) に渡すとどうなるrealloc(でしょうか?私が尋ねるのは、型はchar*そのままですが、ソース サイトで言及されているように、引数はここでもUBになるの"Pointer to a memory block previously allocated with malloc, calloc or realloc.でしょうか?の説明free()free() "If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior."

4

1 に答える 1