Host introspection: Difference between revisions

From Rosetta Code
Content added Content deleted
(Forth)
No edit summary
Line 7: Line 7:
cr 1 here ! here c@ if ." little" else ." big" then ." endian"
cr 1 here ! here c@ if ." little" else ." big" then ." endian"
s" ADDRESS-UNIT-BITS" environment? drop cr . ." bits per address unit (byte)"
s" ADDRESS-UNIT-BITS" environment? drop cr . ." bits per address unit (byte)"
This relies on '''c@''' being a byte fetch (4 chars = 1 cells). Although it is on most architectures, ANS Forth only guarantees that 1 chars <= 1 cells. Some Forths like OpenFirmware have an explicitly sized fetches, like b@.
This relies on '''c@''' being a byte fetch (4 chars = 1 cells). Although it is on most architectures, ANS Forth only guarantees that 1 chars <= 1 cells. Some Forths like OpenFirmware have explicitly sized fetches, like b@.


=={{header|J}}==
=={{header|J}}==

Revision as of 23:45, 10 October 2008

Task
Host introspection
You are encouraged to solve this task according to the task description, using any language you may know.

Print the word size and endianness of the host machine.

Forth

cr 1 cells . ." bytes per cell"
cr 1 here ! here c@ if ." little" else ." big" then ."  endian"
s" ADDRESS-UNIT-BITS" environment? drop cr . ." bits per address unit (byte)"

This relies on c@ being a byte fetch (4 chars = 1 cells). Although it is on most architectures, ANS Forth only guarantees that 1 chars <= 1 cells. Some Forths like OpenFirmware have explicitly sized fetches, like b@.

J

   ":&> (|: 32 64 ;"0 big`little) {"_1~ 2 2 #: 16b_e0 + a. i. 0 { 3!:1 ''  
32
little