From kde-devel Sun May 23 09:42:30 1999 From: Stephan Kulow Date: Sun, 23 May 1999 09:42:30 +0000 To: kde-devel Subject: Re: dumb C++ question X-MARC-Message: https://marc.info/?l=kde-devel&m=92745198725017 Mario Weilguni wrote: > > Am Sun, 23 May 1999 schrieb Stephan Kulow: > >Hi! > > > >What does new int[0]? > > > >In QString (about line 10300) is: > > > > QChar* result = 0; > > uint l = 0; > > if ( str ) { > > if ( maxlen != (uint)-1 ) { > > while (str[l] && l < maxlen) > > l++; > > } else { > > // Faster? > > l = strlen(str); > > } > >-> QChar *uc = new QChar[l]; > > result = uc; > > uint i = l; > > while ( i-- ) > > *uc++ = *str++; > > } > > > >if str == "", then the marked line will > >do new QChar[0]. But what does it return? > >A test said me, it returns something, but > >what does it return? Is it defined? I must > >admit, it's the first time I think about this > >"problem" :) > > It returns the smallest block possible, 16 bytes. It need to return something, > to be able to realloc() it lateron. Hmm, what I've done now is to call malloc(1) when I get a new(0) as malloc(0) is not allowed. Greetings, Stephan -- Und sie nannten ihn, wie er selbst unterschrieb - Den Trojanischen Pferdedieb