* enum { BFD_ENDIAN_BIG, ...}
@ 2001-12-16 17:23 Andrew Cagney
2001-12-16 21:49 ` Ian Lance Taylor
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2001-12-16 17:23 UTC (permalink / raw)
To: binutils; +Cc: gdb
Hello,
I'm curious. Why/how did BFD_ENDIAN_BIG come to be first in the enum:
enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
This has the (intended?) effect of memset(0) setting a value to
BFD_ENDIAN_BIG where as code using the common host dependant BIG_ENDIAN
/ LITTLE_ENDIAN would have treated such a value as undefined.
GDB, which is trying to eliminate its dependance on those host dependant
macros is suffering minor heart burn as a result of the difference - it
has been assuming that ZERO indicated an uninitialized (roughly
BFD_ENDIAN_UNKNOWN) value.
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: enum { BFD_ENDIAN_BIG, ...}
2001-12-16 17:23 enum { BFD_ENDIAN_BIG, ...} Andrew Cagney
@ 2001-12-16 21:49 ` Ian Lance Taylor
2001-12-17 7:30 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2001-12-16 21:49 UTC (permalink / raw)
To: Andrew Cagney; +Cc: binutils, gdb
Andrew Cagney <ac131313@cygnus.com> writes:
> I'm curious. Why/how did BFD_ENDIAN_BIG come to be first in the enum:
>
> enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
I just wrote it that way. Something had to be first.
> This has the (intended?) effect of memset(0) setting a value to
> BFD_ENDIAN_BIG where as code using the common host dependant
> BIG_ENDIAN / LITTLE_ENDIAN would have treated such a value as
> undefined.
I didn't anticipate that the enum would be used in a field which was
not initialized in a normal fashion. I personally pretty much never
privilege a particular element of an enum; either the enum matches an
external definition, in which case all elements have explicit values,
or the enum does not match an external definition, in which case none
of the elements have explicit values. I don't normally initialize
structures using memset(0); I normally explicitly initialize all
fields in one way or another.
> GDB, which is trying to eliminate its dependance on those host
> dependant macros is suffering minor heart burn as a result of the
> difference - it has been assuming that ZERO indicated an uninitialized
> (roughly BFD_ENDIAN_UNKNOWN) value.
It should not break BFD to change the order of the enum values. If it
does, I would consider that to be a bug. If you do change the order,
I would (obviously) recommend an explicit = 0, and a comment
indicating why BFD_ENDIAN_UNKNOWN has a zero value.
Ian
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: enum { BFD_ENDIAN_BIG, ...}
2001-12-16 21:49 ` Ian Lance Taylor
@ 2001-12-17 7:30 ` Andrew Cagney
2001-12-17 16:29 ` Alan Modra
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2001-12-17 7:30 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: binutils, gdb
> Andrew Cagney <ac131313@cygnus.com> writes:
> I didn't anticipate that the enum would be used in a field which was
> not initialized in a normal fashion. I personally pretty much never
> privilege a particular element of an enum; either the enum matches an
> external definition, in which case all elements have explicit values,
> or the enum does not match an external definition, in which case none
> of the elements have explicit values. I don't normally initialize
> structures using memset(0); I normally explicitly initialize all
> fields in one way or another.
I'm currently ``fixing'' gdb to explicitly initialize the relevant field.
>> GDB, which is trying to eliminate its dependance on those host
>> dependant macros is suffering minor heart burn as a result of the
>> difference - it has been assuming that ZERO indicated an uninitialized
>> (roughly BFD_ENDIAN_UNKNOWN) value.
> It should not break BFD to change the order of the enum values. If it
> does, I would consider that to be a bug. If you do change the order,
> I would (obviously) recommend an explicit = 0, and a comment
> indicating why BFD_ENDIAN_UNKNOWN has a zero value.
I'll think about it. While something assuming zero might be a bug, I
really don't want to break BFD.
thanks for the history,
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: enum { BFD_ENDIAN_BIG, ...}
2001-12-17 7:30 ` Andrew Cagney
@ 2001-12-17 16:29 ` Alan Modra
2001-12-17 16:46 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2001-12-17 16:29 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Ian Lance Taylor, binutils, gdb
While we're on this subject, note that initialising pointers (and FP) to
all-bits-zero via memset is not strictly portable. Not all architectures
represent a NULL pointer as all-bits-zero. The C-FAQ mentions a number
of such machines. http://www.eskimo.com/~scs/C-faq/top.html
Alan
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: enum { BFD_ENDIAN_BIG, ...}
2001-12-17 16:29 ` Alan Modra
@ 2001-12-17 16:46 ` Richard Henderson
2001-12-17 17:44 ` Alan Modra
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2001-12-17 16:46 UTC (permalink / raw)
To: Andrew Cagney, Ian Lance Taylor, binutils, gdb
On Tue, Dec 18, 2001 at 10:59:41AM +1030, Alan Modra wrote:
> While we're on this subject, note that initialising pointers (and FP) to
> all-bits-zero via memset is not strictly portable. Not all architectures
> represent a NULL pointer as all-bits-zero. The C-FAQ mentions a number
> of such machines. http://www.eskimo.com/~scs/C-faq/top.html
Whatever. None of them are live.
Nor, IMO, will there ever be another machine created with a non-zero
NULL. The assumption is now so universally ingrained it would cause
more trouble than it would be worth.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: enum { BFD_ENDIAN_BIG, ...}
2001-12-17 16:46 ` Richard Henderson
@ 2001-12-17 17:44 ` Alan Modra
0 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2001-12-17 17:44 UTC (permalink / raw)
To: Richard Henderson; +Cc: Andrew Cagney, Ian Lance Taylor, binutils, gdb
On Mon, Dec 17, 2001 at 04:45:21PM -0800, Richard Henderson wrote:
> On Tue, Dec 18, 2001 at 10:59:41AM +1030, Alan Modra wrote:
> > While we're on this subject, note that initialising pointers (and FP) to
> > all-bits-zero via memset is not strictly portable. Not all architectures
> > represent a NULL pointer as all-bits-zero. The C-FAQ mentions a number
> > of such machines. http://www.eskimo.com/~scs/C-faq/top.html
>
> Whatever. None of them are live.
Heh. I suppose I should have admitted noticing this strict portabilty
problem at various times, and couldn't be bothered fixing occurrences.
The thing is, a number of places in binutils do
memset (structp, 0, sizeof (*structp);
structp->ptr1 = NULL;
structp->ptr2 = NULL;
.
.
as if at some stage binutils authors were concerned about this
portability issue. Typically, not _all_ pointers in the struct are
set to NULL, likely due to bitrot. That's mildly confusing, and should
probably be fixed. My inclination is to remove such "unnecessary"
initialisation.
Alan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-12-18 1:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-16 17:23 enum { BFD_ENDIAN_BIG, ...} Andrew Cagney
2001-12-16 21:49 ` Ian Lance Taylor
2001-12-17 7:30 ` Andrew Cagney
2001-12-17 16:29 ` Alan Modra
2001-12-17 16:46 ` Richard Henderson
2001-12-17 17:44 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox