This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: LittleEndian
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- To: Allan Sandfeld Jensen <snowwolf at one2one-networks dot com>
- Cc: Robert Dewar <dewar at gnat dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 30 Apr 2002 22:30:55 +0200
- Subject: Re: LittleEndian
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <20020429215234.C3DABF28F4@nile.gnat.com> <200204301308.54991.snowwolf@one2one-networks.com>
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)