Message ID | BANLkTikZ9dd_DXPN+=vPE6o-ATnpF_wJ0Q@mail.gmail.com |
---|---|
State | New |
Headers | show |
> this patch fixes an obvious bootstrap issue caused by trying to assign > a constant pointer to an none-constant. > > Index: adaint.c > =================================================================== > > --- adaint.c (revision 174060) > +++ adaint.c (working copy) > @@ -3367,8 +3367,8 @@ > char * > __gnat_to_canonical_file_list_next (void) > { > - static char *empty = ""; > - return empty; > + static char empty[1]; > + return &empty[0]; > } I'm confused. The above looks wrong to me: it does not return an empty string, it returns a pointer to an uninitialized string, which cannot be right (and should generate a warning :-) Arno
On Tue, May 24, 2011 at 11:25:20AM +0200, Arnaud Charlet wrote: > > this patch fixes an obvious bootstrap issue caused by trying to assign > > a constant pointer to an none-constant. > > > > --- adaint.c (revision 174060) > > +++ adaint.c (working copy) > > @@ -3367,8 +3367,8 @@ > > char * > > __gnat_to_canonical_file_list_next (void) > > { > > - static char *empty = ""; > > - return empty; > > + static char empty[1]; > > + return &empty[0]; > > } > > I'm confused. The above looks wrong to me: it does not return an empty string, > it returns a pointer to an uninitialized string, which cannot be right (and > should generate a warning :-) No, static vars are implicitly zero initialized when not explicitly initialized. Jakub
> > I'm confused. The above looks wrong to me: it does not return an empty > > string, > > it returns a pointer to an uninitialized string, which cannot be right > > (and > > should generate a warning :-) > > No, static vars are implicitly zero initialized when not explicitly > initialized. Hmm I see. Still, the above code is not easy to read IMO. I'd suggest instead the following which is easier to read and understand: __gnat_to_canonical_file_list_next (void) { static char empty[] = ""; return empty; } That's actually a change I was about to commit since we've done it recently at AdaCore, so OK with the above variant. Arno
2011/5/24 Arnaud Charlet <charlet@adacore.com>: >> > I'm confused. The above looks wrong to me: it does not return an empty >> > string, >> > it returns a pointer to an uninitialized string, which cannot be right >> > (and >> > should generate a warning :-) >> >> No, static vars are implicitly zero initialized when not explicitly >> initialized. > > Hmm I see. Still, the above code is not easy to read IMO. > > I'd suggest instead the following which is easier to read and understand: > > __gnat_to_canonical_file_list_next (void) > { > static char empty[] = ""; > return empty; > } > > That's actually a change I was about to commit since we've done it recently > at AdaCore, so OK with the above variant. > > Arno Ok applied patch as you suggested at revision 174185. Not sure that sure if this is more readable, but anyway. Regards, Kai
Index: adaint.c =================================================================== --- adaint.c (revision 174060) +++ adaint.c (working copy) @@ -3367,8 +3367,8 @@ char * __gnat_to_canonical_file_list_next (void) { - static char *empty = ""; - return empty; + static char empty[1]; + return &empty[0]; } void