[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: dumb C++ question
From: Mats Loman <lom () wombat ! ludvika ! se>
Date: 1999-05-23 21:31:12
[Download RAW message or body]
On Sun, 23 May 1999, Rik Hemsley wrote:
Well the sizeof(*var) tells that the size of the object the pointer points
at is of size 1 byte, assuming that var is a char.
See:
#include <iostream.h>
main()
{
char *var;
cout << "Without new:" << sizeof(*var) << "\n";
var = new char[0];
cout << "With new char[0]:" << sizeof(*var) << "\n";
delete[] var;
var = new char[100];
cout << "With char[100]:"<< sizeof(*var) << "\n";
delete[] var;
}
Gives:
Without new:1
With new char[0]:1
With char[100]:1
//Mats Loman
>
> Stephan:
>
> > Hmm, what I've done now is to call malloc(1) when
> > I get a new(0) as malloc(0) is not allowed.
>
> Don't bother.
>
> new(0) is ok.
>
> Do a sizeof(*var) and see what you get. With char (not QChar) it should give 1.
>
> Cheers,
> Rik
>
>
> --
> KDE - Colour outside the lines : http://www.kde.org
> [[without]] - software for KDE : http://without.netpedia.net
>
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic