PATCH: String constant initialization

John David Anglin dave@hiauly1.hia.nrc.ca
Wed May 9 14:41:00 GMT 2001


> 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.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)



More information about the Gcc-patches mailing list