This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: String constant initialization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]