"some_type* p_some_type = new some_type [0]" legal?

Discussion in 'C++' started by r.z., Jan 24, 2007.

  1. r.z.

    r.z. Guest

    is it valid to call new [] to allocate 0 elements? If so, is p_some_type
    NULL afterwards?
    r.z., Jan 24, 2007
    #1
    1. Advertising

  2. r.z.

    Guest

    On 24 Jan, 15:02, "r.z." <> wrote:
    > is it valid to call new [] to allocate 0 elements? If so, is p_some_type
    > NULL afterwards?


    Yes, No.

    Allocating 0 elements returns non-NULL pointer. The pointer will be
    different each time. It's not legal to dereference the pointer, but it
    is legal to pass it to delete[].

    Usually this is exactly what you want.
    , Jan 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valentin Tihomirov

    Is this legal?

    Valentin Tihomirov, Oct 21, 2003, in forum: VHDL
    Replies:
    20
    Views:
    1,214
    Jan Decaluwe
    Oct 29, 2003
  2. Divyang M
    Replies:
    9
    Views:
    603
    Divyang M
    May 18, 2005
  3. Divyang M
    Replies:
    1
    Views:
    552
    Jerzy Gbur
    May 15, 2005
  4. Weng Tianxiang
    Replies:
    12
    Views:
    1,373
  5. =?Utf-8?B?RGF2ZQ==?=

    Legal ViewState Characters

    =?Utf-8?B?RGF2ZQ==?=, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    351
    Patrice
    May 24, 2004
Loading...

Share This Page