What is the difference

char* data1;
char* data2;


data1 = new char(200);
data2 = new char[200];


Thanks in advance
1
2
data1 = new char(200);  // data1 points to a single char with value 200.
data2 = new char[200];  // data2 points to an array of 200 char with unspecified values. 
Thanks..
Actually,

data1 = new char(200);

usually results in a value of -56

(char is signed, by default, with Visual C++ and GCC; not sure about Clang, but I suspects it's the same.)

Andy
Last edited on
Thanks Andy,
> char is signed, by default, with Visual C++ and GCC; not sure about Clang, but I suspects it's the same.

In practice, whether char is a signed integral type or not depends on the hardware platform, and not on the vendor of the compiler. For instance, with all three compilers (Microsoft C++, gcc and clang) char is signed on x86 platforms and unsigned on MIPS platforms.
My mind is a bit hazy as it's so long ago...

But I thought the Microsoft compiler used the same char type across all the platforms it used to support: i386, DEC Alpha, PowerPC and MIPS. I remember all kinds of memory alignment issues, but nothing to do with sign issues.

Checking MSDN I see all versions of the compiler for mobile devices share the /J switch (which changes the default char type from signed to signed) with the regular compiler. And the ARM cross-compiler provided with Visual Studio 2012 also has this /J switch.

Andy
Topic archived. No new replies allowed.