"John Marshall" <[EMAIL PROTECTED]> wrote in message
news:41474@palm-dev-forum...
>
> Ben Combee <[EMAIL PROTECTED]> wrote:
> > Huh?  CW honors the \0 escape for both character literals and strings.
I
> > should know -- I rewrote a lot of that escape parsing code.
> [...]
> > The problem here is actually that the user is specifying a string of 11
> > characters -- even with the escaped NULs, there still is the terminating
> > NUL.
>
> Huh?  I hope you weren't labouring under this misconception when you
> rewrote that escape parsing code!  (Well, I suppose initialisation is
> separate enough from parsing escapes that there wouldn't have been a
> problem.)

No, I was thinking about the string constant creation code, specifically
some of the pooling code that I worked on for the x86 compiler.  For
initialization, the exact size of the array is used -- but that init code is
built based on the constant string which had already been analyzed by the
compiler, just not yet put into a data or text segment.  However, if you
said:

char foo[] = "\0\0\0";

which is equivalent to

char foo[] = { '\0', '\0', '\0', '\0' };

so sizeof(foo) == 4, since its inferred from the size of the constant string
which is four in this case.

> > And, as Aaron pointed out, if you specify a partial array in C, the
> > compiler is obligated to zero-fill.
>
> Indeed, "char s[5] = { 'a', 'b', 'c' };" is required to initialise s[3]
and
> s[4] to '\0'.  This is true for "char s[5] = "abc";" too in C99 (section
> 6.7.8 paragraph 21), but if there's an equivalent requirement in C89 I
> haven't seen it.
>
>     John  "must stamp out misleading pedantry! :-)  especially on
Fridays!"

I had a misleaning pantry once -- it collapse, scattering soup cans across
the room.

--
Ben Combee
Veriprise Wireless <http://www.veriprise.com>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to