Why didn't ANSI make initialisation consistent ????

Dale Worley worley at compass.com
Fri Apr 26 00:51:07 AEST 1991


In article <1991Apr24.141206.18103 at grep.co.uk> vic at grep.co.uk (Victor Gavin) writes:
   I traced it back to my use of
	   char *fred = "bert"

   Could anyone tell me whether the ANSI committee pondered over the problem of
   tidying up the inconsistencies of the C initializations ?

Actually, initializations *are* consistent -- other than the object
named in the declaration, an initialization *never* allocates memory.
What is allocating the "extra" memory is the string literal "bert".
String literals *always* allocate memory for themselves, except in the
special case when they are used as the initializer for an array of
chars.  For instance,

	char *p;

	p = "1234";

allocates 5 bytes of memory to hold the string literal.

Dale Worley		Compass, Inc.			worley at compass.com
--
So you want to have a shameful affair?
Yet, somehow you can't justify it?

The next time you are contemplating a decision in which you are debating
whether or not to go for the gusto, ask yourself this Important Question:

	How long will I be dead?

With that perspective, you can now make a free, fearless choice to do
just about any goddamned sneaky thing your devious little mind can think
up.  Go ahead.  Have your fun.  You're welcome.  Go on.  See you in
Hell.
		--Matt Groening



More information about the Comp.lang.c mailing list