>>>>> On Wed, 9 Sep 2009 08:16:46 +0200, Kern Sibbald said:
>
> On Tuesday 08 September 2009 21:49:51 lorenz schori wrote:
> > Hi
> >
> > On 08.09.2009, at 20:50, Martin Simmons wrote:
> > >>>>>> On Tue, 8 Sep 2009 17:38:01 +0200, Kern Sibbald said:
> > >>
> > >> On Tuesday 08 September 2009 17:04:39 Eric Bollengier wrote:
> > >>> Hello Lorenz,
> > >>>
> > >>> I don't understand very well why the current code doesn't work,
> > >>> what is the
> > >>> diffrence between the #ifdef and the if(htonl(1) == 1L) ?
> > >>>
> > >>> They should produce the same thing, isn't it ?
> > >>
> > >> The answer is yes, they should produce the same thing. However,
> > >> Lorenz wants
> > >> to produce chip independent binaries for the Mac so the same binary
> > >> can run
> > >> on Intel and the older Macs (if I understand right), and to do so,
> > >> byte order
> > >> differences must be resolved at execution time rather than compile
> > >> time.
> > >
> > > Kind of -- it only runs configure once, so it can't be decided then.
> >
> > Yes, that's right. I thought about running the complete configure/make
> > independently for each architecture and fusing together the binaries
> > using the lipo command - or even abandon universal binaries and just
> > put together an installer package for each architecture. If however
> > the only problem with the current method is the one in md5.c, I
> > happily stick with the current mechanism. The build process is faster
> > and the Makefile less complex...
> >
> > >>>>> [...]
> > >>>>> if (htonl(1) == 1L) {
> > >
> > > What a brilliant use of abstraction :-(
> >
> > A more expressive endian check would be something like the following
> > function (see also: http://c-faq.com/misc/endiantest.html)
> >
> > #include <stdio.h>
> >
> > inline int bigendian() {
> > const int number_one = 1;
> > const char first_byte_of_number_one = *(char*)&number_one;
> >
> > return first_byte_of_number_one==0;
> > }
>
> I much prefer the code we have, but as I expect was Martin's point, I was
> already considering that we should probably move it into a an inline
> subroutine. The place for such subroutines is in src/baconfig.h. It would
> then make the code much easier to read.
>
> inline bool bigendian() {
> return htonl(1) == 1L);
> }
Yes, that's what I meant really. The algorithm is incidental, but it is
better to keep it in one place with a descriptive name.
__Martin
|