掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
new long [0] の解放 (ID:58699)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> new long [0]で取得したポインタに対して、 > delete [] を実行させた場合、問題は発生しませんか? operator new[]とoperator delete[]に問題がなければ, 問題は発生しません。 > long *lp = new long[0]; ←この地点でコンパイラがエラーを吐かないのかな? INCITS/ISO/IEC 14882:2003 5.3.4 New / Paragraph. 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. というわけで,コンパイラはエラーを吐きません。 また,operator new[]は記憶域を割り付けます。 ちなみにmallocと違い,要求サイズ0の時にoperator new/operator new[]がヌルポインタ定数を返すことはありません。 # 同 3.7.3.1 Allocation functions / Paragraph. 2 > でも delete は NULL に対しては何も行わないんだっけか? 行いません。 同 5.3.5 Delete / Paragraph. 2 >... In either alternative, >if the value of the operand of delete is the null pointer the operation has no effect. ...
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.