This is the mail archive of the
mailing list for the GCC project.
Re: PATCH: String constant initialization
- To: neil at daikokuya dot demon dot co dot uk (Neil Booth)
- Subject: Re: PATCH: String constant initialization
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- Date: Wed, 9 May 2001 17:41:16 -0400 (EDT)
- Cc: gcc-patches at gcc dot gnu dot org
> Cool. If you get the go-ahead, could you close the PR with exactly
> this problem? It's PR 128 I think.
I have no idea how to close a PR.
> > (TREE_CODE (exp) == STRING_CST
> > - ? TREE_STRING_LENGTH (exp)
> > + ? (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
> > + ? MAX (TREE_STRING_LENGTH (exp),
> > + int_size_in_bytes (TREE_TYPE (exp)))
> > + : TREE_STRING_LENGTH (exp))
> > : int_size_in_bytes (TREE_TYPE (exp))));
> Just curious, since I'm trying to understand the C front end myself.
> Why is int_size_in_bytes() not always the right thing to pass? If the
> string is longer, can't we just drop the extra bytes?
I believe that int_size_in_bytes() can be zero if you declare the string
array like `char s = "xyz";'. I think this is the only situation
where the array size can be smaller than the string length. The compiler
generates an error if the initialisation string is longer than an
explicitly declared array size.
J. David Anglin firstname.lastname@example.org
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)