This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: LittleEndian


Allan Sandfeld Jensen wrote:

> Sometimes it just practical if you want to retain your bitfidling algorithms
> from one architecture to another. Ofcouse personally I would prefer to have
> it as a syntax option to int. E.g. "little_endian long int" or just "le
> long". The ELF-flag would then just specify which is default.

Why do you want syntax to determine endianness ?  Surely it's detectable
at run time.

Here's the Fortran implementation:

      SUBROUTINE ENDIANP
      INTEGER*1 IBITS(10)
      LOGICAL LITTLE
      COMMON /ENDIAN/ LITTLE
      EQUIVALENCE (IBITS, JBITS)
      NWBITS = BIT_SIZE(JBITS)
      NBBITS = BIT_SIZE(IBITS(1))
      DO I = 1, NWBITS, NBBITS
         IBITS(I/NBBITS+1) = I
      ENDDO
      LITTLE = .TRUE.
      KBITS  = JBITS
      DO I = 1, NWBITS, NBBITS
         LITTLE = LITTLE .AND.
     ,               IAND(KBITS,2**NBBITS-1) .EQ. IBITS(I/NBBITS+1)
         KBITS = ISHFT(KBITS, -NBBITS)
      ENDDO
      END

In the routines where you need to know enddiannes, simply declare the
COMMON block:

      ....
      LOGICAL LITTLE
      COMMON /ENDIAN/ LITTLE
      ....
      IF (LITTLE) THEN
         ... ! Little endian branch
      ELSE
         ... ! Big endian branch
      ENDIF
      ...

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


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