Host introspection: Difference between revisions

Content added Content deleted
No edit summary
(Correction to non-portable code)
Line 191: Line 191:
=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
<lang fortran>INTEGER, PARAMETER :: i8 = SELECTED_INT_KIND(2)
<lang fortran> integer :: i
character(len=1) :: c(20)
INTEGER, PARAMETER :: i16 = SELECTED_INT_KIND(4)
equivalence (c, i)
INTEGER(i8) :: a(2)
INTEGER(i16) :: b


WRITE(*,*) bit_size(1) ! number of bits in the default integer type
WRITE(*,*) bit_size(1) ! number of bits in the default integer type
! which may (or may not!) equal the word size
! which may (or may not!) equal the word size
i = 1


IF (ichar(c(1)) == 0) THEN
b = Z'1234' ! Hexadecimal assignment
WRITE(*,*) "Big Endian"
a = (TRANSFER(b, a)) ! Split a 16 bit number into two 8 bit numbers
ELSE

WRITE(*,*) "Little Endian"
IF (a(1) == Z'12') THEN ! where did the most significant 8 bits end up
END IF</lang>
WRITE(*,*) "Big Endian"
ELSE
WRITE(*,*) "Little Endian"
END IF</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==