[prog] [C] strings bug

Jimen Ching jching at flex.com
Fri Apr 11 00:19:20 EST 2003

On Fri, 11 Apr 2003, Dan Richter wrote:
>   int a();

How do you know whether this is a function prototype declaration or a
variable declaration?  According to the ANSI C++ standard, this is a
function prototype declaration.  I.e. 'a' is a function taking void, and
returning int.

>   int* p = new int();

This is valid, and GCC 2.95.4 handles it just fine.

>I would also note that, with the GCC, all ints allocated using "new" are
>automatically initialized to zero.

Only for the case of:

	int *i = new int();

which calls the default constructor, which sets the variable to zero.
Without the parenthesis, the returned memory is uninitialized.  See
section 8.5 of ISO/IEC 14882.

>But let me finish by saying that depending on automatic intialization is
>a really bad idea.

C++ gives you a rope to shoot your leg off.  But if you know how to use
the rope...

Jimen Ching (WH6BRR)      jching at flex.com     wh6brr at uhm.ampr.org

More information about the Programming mailing list