2 bytes allocated problems

Max Laier max at love2party.net
Thu Feb 25 22:53:54 UTC 2010


On Thursday 25 February 2010 23:46:03 Dag-Erling Smørgrav wrote:
> "Matthias Andree" <matthias.andree at gmx.de> writes:
> > Dag-Erling Smørgrav <des at des.no> writes:
> > > char a[9] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
> >
> > char a[9] = "abcdefghi";
> >
> > suffices. The compiler knows there isn't room for the terminal '\0'
> > and omits it.
> 
> Some compilers (gcc at least) warn about it.

It shouldn't.  C99 explicitly has this as an example (6.7.8.32).  It's also of 
note that
  char *p = "abc"
is different from
  char a[] = "abc"
in that the elements of a are modifiable, while modifying p[x] yields 
undefined behavior.

But this is increasingly getting out of scope for hackers@ ... so I'll shut up 
now.

--
  Max


More information about the freebsd-hackers mailing list