Host introspection: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Added Bash / Unix Shell Implementation) |
m (→{{header|Wren}}: Minor tidy) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 16:
It's not possible to get the word size without knowing it in advance. But the 68000's big-endian nature can easily be proven even if the programmer didn't know that it was big-endian already.
Code is called as a subroutine, i.e. <code>JSR TestEndianness</code>. Hardware-specific print routines are unimplemented.
<
LEA UserRam,A0
MOVE.L #$0000FFFF,(A0)
Line 36:
LittleEndianMessage:
DC.B "LITTLE-ENDIAN",0
EVEN</
=={{header|8086 Assembly}}==
As with [[68000 Assembly]], there's no way to "prove" the word size without knowing it in advance. But endianness can still be tested for quite easily.
<
.stack 1024
Line 64:
int 21h ;return to MS-DOS
end start</
If the 8086 is little-endian, BX will equal 0022, since we loaded the low byte of UserRam into BL (the low half of BX). If it's big-endian, BX will equal 0034.
Line 80:
=={{header|Action!}}==
<
PrintE("All Atari 8-bit computers use little-endian word of 16-bits size.")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Host_introspection.png Screenshot from Atari 8-bit computer]
Line 90:
=={{header|Ada}}==
<
with System; use System;
Line 97:
Put_Line ("Word size" & Integer'Image (Word_Size));
Put_Line ("Endianness " & Bit_Order'Image (Default_Bit_Order));
end Host_Introspection;</
{{out|Sample output on a Pentium machine}}
Line 110:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of FORMATted transput}}
<
INT bits per char = ENTIER (ln(max abs char+1)/ln(max abs bit+1));
INT bits per int = ENTIER (1+ln(max int+1.0)/ln(max abs bit+1));
Line 133:
int byte order +:= REPR(abcdi OVER (max abs bit+1) ** shift MOD (max abs char+1))
OD;
printf(($"int byte order: "g,", Hex:",16r8dl$,int byte order, BIN abcdi))</
{{out}} (Intel i686):
<pre>
Line 160:
=={{header|Applesoft BASIC}}==
<
2 DATA6,24,251,144,2,251,56
3 DATA216,105,0,133,251,96
Line 171:
10 IF M THEN PRINT M$
11 PRINT "ENDIANNESS: ";
12 PRINT "LITTLE-ENDIAN"</
=={{header|ARM Assembly}}==
Line 178:
The ARM CPU's endianness can be set to either little-endian or big-endian. Not all ARM CPUs have this feature, but this test will work regardless of whether the endian switch features exist on any particular model or not. The easiest way to test endianness is to write a word to RAM, then read the 0th byte from that memory location and see what it is. (The example below uses VASM syntax.)
<
mov r0,#0xFF
mov r1,#0x02000000 ;an arbitrary memory location on the Game Boy Advance.
Line 187:
cmp r0,#0
beq isBigEndian
;else, do whatever is needed to display "little-endian" to the screen. This part isn't implemented.</
=={{header|Babel}}==
<
{ "Word size: " << msize 3 shl %d << " bits" cr <<
"Endianness: " << { endian } { "little" } { "big" } ifte cr << }</
=={{header|BBC BASIC}}==
<
!P% = -1
I% = 0 : REPEAT I% += 1 : UNTIL P%?I%=0
Line 200:
!P% = 1
IF P%?0 = 1 THEN PRINT "Little-endian"
IF P%?(I%-1) = 1 THEN PRINT "Big-endian"</
The 'word size' is reported as the number of bytes accessed by the ! indirection operator, which is 4 in all current versions of BBC BASIC.
=={{header|C}}==
<
#include <stddef.h> /* for size_t */
#include <limits.h> /* for CHAR_BIT */
Line 225:
printf("big endian\n");
return 0;
}</
On POSIX-compatible systems, the following also tests the endianness (this makes use of the fact that network order is big endian):
<
#include <arpa/inet.h>
Line 237:
else
printf("little endian\n");
}</
=={{header|C sharp}}==
<
{
Console.WriteLine("Word size = {0} bytes,",sizeof(int));
Line 248:
else
Console.WriteLine("Big-endian.");
}</
=={{header|C++}}==
<
#include <iostream>
Line 267:
std::cout << "host is little-endian\n";
}
}</
{{out}}
<pre>
Line 285:
=={{header|Clojure}}==
<
(println "endianness: " (System/getProperty "sun.cpu.endian"))</
=={{header|Common Lisp}}==
Line 293:
The [http://www.lispworks.com/documentation/HyperSpec/Body/c_enviro.htm Environment] has some implementation-specific functions that might provide a good hint, e.g.,
<
The [http://www.cliki.net/features *features*] list also provides useful information, e.g., some compilers declare :LITTLE-ENDIAN there.
Line 300:
=={{header|D}}==
<
import std.stdio, std.system;
writeln("Word size = ", size_t.sizeof * 8, " bits.");
writeln(endian == Endian.littleEndian ? "Little" : "Big", " endian.");
}</
{{out}}
<pre>Word size = 64 bits.
Line 311:
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 320:
Writeln('word size: ', SizeOf(Integer));
Writeln('endianness: little endian'); // Windows is always little endian
end.</
=={{header|Erlang}}==
To find the word size:
<
4</
In the case of endianness, Erlang's bit syntax by default has a 'native' option which lets you use what is supported natively.
Line 331:
However, one could write one by using bit syntax, setting endianness and then comparing to the native format:
<
<<1,0,0,0>>
2> <<1:4/big-unit:8>>
<<0,0,0,1>>
3> <<1:4/little-unit:8>>.
<<1,0,0,0>></
And so the following function would output endianness:
<
endianness() -> little.</
=={{header|F_Sharp|F#}}==
A lot of research before I finally came up with an answer to this that isn't dependent on the machine it was compiled on. Works on Win32 machines only (obviously, due to the interop). I think that strictly speaking, I should be double checking the OS version before making the call to wow64Process, but I'm not worrying about it.
<
open System.Runtime.InteropServices
open System.Diagnostics
Line 358:
f64Bit
let IsLittleEndian() = BitConverter.IsLittleEndian
(IsLittleEndian(), Is64Bit())</
=={{header|Factor}}==
<
"Word size: " write cell 8 * .
"Endianness: " write little-endian? "little" "big" ? print</
=={{header|Forth}}==
<
cr 1 cells . ." address units per cell"
s" ADDRESS-UNIT-BITS" environment? if cr . ." bits per address unit" then
cr 1 here ! here c@ if ." little" else ." big" then ." endian" ;</
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|Fortran}}==
{{works with|Fortran|90 and
<
character(len=1) :: c(20)
equivalence (c, i)
Line 386:
ELSE
WRITE(*,*) "Little Endian"
END IF</
{{works with|Fortran| 77 and later}}
<syntaxhighlight lang="fortran">
PROGRAM endianness
IMPLICIT NONE
INTEGER(KIND=4) :: i = 1
!ISHFT(INTEGER, SHIFT) : Left shift if SHIFT > 0
!ISHFT(INTEGER, SHIFT) : Right shift if SHIFT < 0
IF (ISHFT(i,1) .EQ. 0) THEN
WRITE(*,FMT='(A)') 'Architechture is Big Endian'
ELSE
WRITE(*,FMT='(A)') 'Architecture is Little Endian'
END IF
RETURN
STOP
END PROGRAM endianness
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
' uses intrinsic defines, set by the compiler
Line 405 ⟶ 424:
#EndIf
Sleep</
{{out}}
Line 414 ⟶ 433:
=={{header|Frink}}==
<
println["Word size: " + callJava["java.lang.System", "getProperty", "sun.arch.data.model"]]
println["Endianness: " + callJava["java.lang.System", "getProperty", "sun.cpu.endian"]]
</syntaxhighlight>
=={{header|Go}}==
<
import (
Line 490 ⟶ 509:
}
}
}</
{{out}}
<pre>
Line 523 ⟶ 542:
</pre>
Alternative technique:
<
import (
Line 539 ⟶ 558:
fmt.Println(f.FileHeader.ByteOrder)
f.Close()
}</
{{out}}
<pre>
Line 547 ⟶ 566:
=={{header|Groovy}}==
Solution follows [[Java]]:
<
println "endianness: ${System.getProperty('sun.cpu.endian')}"</
{{out}}
Line 555 ⟶ 574:
=={{header|Haskell}}==
<
import ADNS.Endian -- http://hackage.haskell.org/package/hsdns
Line 562 ⟶ 581:
putStrLn $ "Endianness: " ++ show endian
where
bitsize = show $ bitSize (undefined :: Int)</
=={{header|Icon}} and {{header|Unicon}}==
<
write(if 0 = ishift(1,-1) then "little" else "big"," endian")
if match("flags",line := !open("/proc/cpuinfo")) then # Unix-like only
write(if find(" lm ",line) then 64 else 32," bits per word")
else write("Cannot determine word size.")
end</
Sample run:
Line 584 ⟶ 603:
=={{header|J}}==
<
64</
This returns <code>32</code> in 32 bit J.
This value could also be calculated, exercising left shift of bits in a 2s complement fixed width integer:<syntaxhighlight lang="j"> 2+2^.>./1&(33 b.)^:a:1
64</syntaxhighlight>
Note that this mechanism is testing the interpreter, and not the OS or Hardware. (Though, of course, you cannot run a 64 bit interpreter on a machine that does not support it.)
Line 593 ⟶ 615:
That said, this does not deal with endianness. For the most part, J programs do not need to know their own endianness. When converting to and from binary format you can specify "native", "little endian" and "big endian", and it's rare that you have an interface which would need anything else. That said, you can inspect the binary representation of a simple constant:
<
64
little</
=={{header|Java}}==
Line 602 ⟶ 624:
{{works with|Java|1.4}}
<
public class ShowByteOrder {
Line 609 ⟶ 631:
System.out.println(ByteOrder.nativeOrder());
}
}</
Some JVMs also have system properties for the word size and byte order.
<
System.out.println("endianness: "+System.getProperty("sun.cpu.endian"));</
=={{header|Julia}}==
<code>Julia</code> creates <code>ENDIAN_BOM</code> a 32 bit unsigned integer out of an array of 4 8 bit unsigned integers to serve as an endianness marker.
<syntaxhighlight lang="julia">
print("This host's word size is ", WORD_SIZE, ".")
if ENDIAN_BOM == 0x04030201
Line 627 ⟶ 649:
println("ENDIAN_BOM = ", ENDIAN_BOM, ", which is confusing")
end
</syntaxhighlight>
{{out}}
Line 636 ⟶ 658:
=={{header|Kotlin}}==
The following is not guaranteed to work on all JVMs but is working fine on my x64 Windows 10 machine:
<
fun main(args: Array<String>) {
println("Word size : ${System.getProperty("sun.arch.data.model")} bits")
println("Endianness: ${System.getProperty("sun.cpu.endian")}-endian")
}</
{{out}}
Line 651 ⟶ 673:
=={{header|Lua}}==
Pure/native Lua can't do this (and essentially doesn't care). However, Lua is often used in a scripting environment, where such issues may be important, and any needed support would be expected to be provided by the host or some other external library. Here using ffi:
<
print("size of int (in bytes): " .. ffi.sizeof(ffi.new("int")))
print("size of pointer (in bytes): " .. ffi.sizeof(ffi.new("int*")))
print((ffi.abi("le") and "little" or "big") .. " endian")</
{{out}}
<pre>size of int (in bytes): 4
Line 661 ⟶ 683:
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
\\ Always run in Little-endian, 32 bits (in Wow64 in 64 bit os)
Line 691 ⟶ 713:
}
Checkit
</syntaxhighlight>
=={{header|MACRO-10}}==
<syntaxhighlight lang="macro-10">
title Host Introspection
subttl PDP-10 assembly (MACRO-10 on TOPS-20). KJX 2022.
Line 729 ⟶ 751:
end start
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
$SystemWordLength "bits"</
{{out}} x86
Line 745 ⟶ 767:
The concept of "word size" is not meaningful in Matlab and Octave, uint64 is also available on 32bit-platforms, and there are no pointers. Endianity can be tested with the function below:
<
fid=tmpfile();
fwrite(fid,1:8,'uint8');
Line 762 ⟶ 784:
else endian='little';
end;
</syntaxhighlight>
{{out}}
Line 774 ⟶ 796:
As I've come to find out, MIPS is a bi-endian architecture (meaning its endianness is implementation-defined rather than a constant trait of the CPU.) In particular, the PlayStation 1 is little-endian, and the Nintendo 64 is big-endian. This can be proven with the test below. (Hardware-specific routines <code>MonitorA0A1RAPC</code> and <code>MemDump</code> are omitted just to keep things brief.)
<
nop ;on the PlayStation, the instruction AFTER a branch gets executed BEFORE the branch actually occurs.
;The Nintendo 64 didn't have this "feature" but for compatibility's sake
Line 804 ⟶ 826:
.byte 0xF3,0xF2,0xF1,0xF0 ;this will load as F0F1F2F3 on little-endian machines, and as-is on big-endian
.word 0xF0F1F2F3 ;this will load as F0F1F2F3 regardless of endianness.
</syntaxhighlight>
{{out}}
Register Dump of PlayStation 1:
Line 815 ⟶ 837:
=={{header|Modula-3}}==
<
IMPORT IO, Fmt, Word, Swap;
Line 826 ⟶ 848:
IO.Put("Endianness: Little\n");
END;
END Host.</
{{out}} (on an x86):
Line 839 ⟶ 861:
C support file, host-introspection.c
<
/* From Rosetta Code, C entry, with Neko marshalling */
Line 854 ⟶ 876:
}
/* Expose symbol to Neko loader */
DEFINE_PRIM(wordsize, 0);</
Neko caller, host-introspection.neko
<syntaxhighlight lang="actionscript">/**
Host introspection, in Neko
*/
Line 873 ⟶ 895:
var wordsize = $loader.loadprim("native@wordsize", 0)
$print("wordsize: ", wordsize(), " bits\n")</
{{out}}
Line 886 ⟶ 908:
{{trans|Java}}
NetRexx can access this information from the [[Java]] virtual machine in the same way as the [[#Java|Java]] sample above.
<
options replace format comments java crossref savelog symbols nobinary
Line 894 ⟶ 916:
say ' word size:' wordSize
say 'endianness:' endian
</syntaxhighlight>
=={{header|Nim}}==
In Nim, "int" type has the size of the word. So, to find the word size in bits, just multiply the "int" size in bytes by eight.
<
echo sizeof(int) * 8</
=={{header|Objective-C}}==
Endianness:
<
case NS_BigEndian:
NSLog(@"%@", @"Big Endian");
Line 913 ⟶ 935:
NSLog(@"%@", @"endianness unknown");
break;
} </
Architecture:
(works on Mac OS X 10.6+)
<
case NSBundleExecutableArchitectureI386:
NSLog(@"%@", @"i386 32-bit");
Line 937 ⟶ 959:
NSLog(@"%@", @"Unknown");
break;
}</
=={{header|OCaml}}==
<
Printf.printf "%s\n" Sys.os_type; (* Print operating system *)</
{{works with|OCaml|4.00+}}
<
Printf.printf "%s\n" (if Sys.big_endian then "big endian" else "little endian");</
On OCaml 3 and below, there are tricks to get endianness. For example in Linux or Unix variants,
one may use the [http://unixhelp.ed.ac.uk/CGI/man-cgi?uname uname] shell command :
<
let arg = if arg = "" then "-" else arg in
let ic = Unix.open_process_in ("uname -" ^ arg) in
Line 958 ⟶ 980:
# uname "sm";;
- : string = "Linux i686"</
In most cases, endianness can be infered from informations given by uname.
Line 964 ⟶ 986:
One may also read files in the /proc directory in order to get informations about the host, only under linux :
<
If the loop is implemented by a recursive auxiliary function, the try...with breaks
tail recursion if not written carefully *)
Line 997 ⟶ 1,019:
"VmallocChunk: 109320 kB"; "HugePages_Total: 0";
"HugePages_Free: 0"; "HugePages_Rsvd: 0";
"HugePages_Surp: 0"; "Hugepagesize: 4096 kB"]</
Same methods can be used to get the results of commands lshw, dmidecode...
=={{header|Pascal}}==
<
begin
writeln('Pointer size: ', SizeOf(Pointer), ' byte, i.e. ', SizeOf(Pointer)*8, ' bit.');
Line 1,010 ⟶ 1,032:
else
writeln('This host is little endian.');
end.</
{{out}}
<pre>
Line 1,020 ⟶ 1,042:
=={{header|Perl}}==
Most basic example:
<
print "UV size: $Config{uvsize}, byte order: $Config{byteorder}\n";</
{{out}}
<pre>
Line 1,028 ⟶ 1,050:
More verbose example:
<
use Config;
my ($size, $order, $end) = @Config{qw(uvsize byteorder)};
Line 1,036 ⟶ 1,058:
default { $end = 'mixed' }
}
say "UV size: $size, byte order: $order ($end-endian)";</
{{out}}
<pre>
Line 1,051 ⟶ 1,073:
Note that machine_word() and machine_bits() test the interpreter or compiled executable, rather than the OS or hardware.<br>
Also, all known implementations of Phix are currently little-endian. See also platform(), which yields WINDOWS/LINUX/JS.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">endianness</span><span style="color: #0000FF;">()</span>
Line 1,072 ⟶ 1,094:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Endianness: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">endianness</span><span style="color: #0000FF;">()})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Word size: %d bytes/%d bits\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">(),</span><span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()})</span>
<!--</
{{out}}
<pre>
Line 1,094 ⟶ 1,116:
other contributions to this task) only tells how the binary was
compiled/assembled/linked, not necessarily the nature of the underlying system.
<
(rd 4) # Skip "7F" and 'E', 'L' and 'F'
(prinl
Line 1,105 ⟶ 1,127:
(1 "Little endian")
(2 "Big endian")
(T "Bad EI_DATA") ) ) )</
{{out}}
<pre>64 bits
Line 1,111 ⟶ 1,133:
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
details: procedure options (main); /* 6 July 2012 */
declare x float, i fixed binary initial (1);
Line 1,123 ⟶ 1,145:
end details;
</syntaxhighlight>
{{out}}
<pre>
Line 1,131 ⟶ 1,153:
=={{header|PowerShell}}==
<
Write-Host -NoNewLine "Endianness: "
if ([BitConverter]::IsLittleEndian) {
Line 1,137 ⟶ 1,159:
} else {
Write-Host Big-Endian
}</
Note that endianness is essentially a moot point with PowerShell,
as there is only a Windows implementation currently
Line 1,144 ⟶ 1,166:
=={{header|PureBasic}}==
<
#LittleEndian
#BigEndian
Line 1,167 ⟶ 1,189:
PrintN("and you use Big Endian.")
EndSelect
EndIf</
=={{header|Python}}==
<
>>> platform.architecture()
('64bit', 'ELF')
Line 1,183 ⟶ 1,205:
>>> socket.gethostname()
'yourhostname'
>>></
=={{header|R}}==
Word size
<
Endianness
<
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket/base
(printf "Word size: ~a\n" (system-type 'word))
(printf "Endianness: ~a\n" (if (system-big-endian?) 'big 'little))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
Endian detection translated from C. {{works with|Rakudo|2018.03}}
<syntaxhighlight lang="raku"
say $*VM.config<ptr_size>;
my $bytes = nativecast(CArray[uint8], CArray[uint16].new(1));
say $bytes[0] ?? "little-endian" !! "big-endian";</
{{out}}
<pre>8
Line 1,211 ⟶ 1,233:
Note: Rakudo 2018.12 is introducing the endian-sensitive<code>read-int16</code> method,
which makes endian detection a little easier:
<syntaxhighlight lang="raku"
In Rakudo 2019.01 the dynamic KERNEL variable was fleshed out with a bunch of accessors, among them:
<syntaxhighlight lang="raku"
{{out}}
<pre>linux, 64, x86_64, LittleEndian</pre>
Line 1,223 ⟶ 1,245:
Word Size
<
^variations'size</
Returns the number of bits per cell. This is normally 32, though may be smaller or larger on embedded systems and under special cases.
Line 1,230 ⟶ 1,252:
Endianness
<
^variations'endian</
Returns 0 for little endian, and 1 for big endian.
Line 1,241 ⟶ 1,263:
<br>However, there is a STORAGE built-in function that allows a program to look at (local) storage, and if there is an
<br>indicator stored anywhere in the virtual address space, it can be examined.
<
parse source opSys howInvoked pathName
/*where opSys will indicate which operating system REXX is running under, and */
/*from that, one could make assumptions what the wordsize is, etc. */</
=={{header|Ruby}}==
<
# Fixnum#size returns bytes (1 byte = 8 bits).
word_size = 42.size * 8
Line 1,258 ⟶ 1,280:
bytes = [1].pack('S').unpack('C*')
byte_order = (bytes[0] == 0 ? 'big' : 'little') + ' endian'
puts "Byte order: #{byte_order}"</
With [[MRI]], <code>ri Fixnum</code> states, "A Fixnum holds Integer values that can be represented in a native machine word (minus 1 bit)." This bases our claim that a Fixnum occupies one machine word.
Line 1,265 ⟶ 1,287:
=={{header|Rust}}==
<
enum Endianness {
Big, Little,
Line 1,286 ⟶ 1,308:
println!("Word size: {} bytes", std::mem::size_of::<usize>());
println!("Endianness: {:?}", Endianness::target());
}</
{{out}}
Line 1,293 ⟶ 1,315:
=={{header|Scala}}==
{{libheader|Scala}}<
object ShowByteOrder extends App {
Line 1,299 ⟶ 1,321:
println(s"Word size: ${System.getProperty("sun.arch.data.model")}")
println(s"Endianness: ${System.getProperty("sun.cpu.endian")}")
}</
=={{header|Scheme}}==
{{works with|Chicken Scheme}}<
(begin
(display "Endianness: ")
Line 1,309 ⟶ 1,331:
(display "Word Size: ")
(display (if (fixnum? (expt 2 33)) 64 32))
(newline)))</
{{out}}
Endianness: little-endian
Line 1,318 ⟶ 1,340:
The example below assumes that the word size is the size of a pointer.
<
include "cc_conf.s7i";
Line 1,330 ⟶ 1,352:
writeln("Big endian");
end if;
end func;</
{{out}}
Line 1,339 ⟶ 1,361:
=={{header|Slate}}==
<
inform: 'Word Size: ' ; (Platform current bytesPerWord * 8) printString.</
{{out}}
<pre>
Line 1,349 ⟶ 1,371:
=={{header|Tcl}}==
This is very straightforward in Tcl. The global array <code>tcl_platform</code> contains these values. In an interactive <code>tclsh</code>:
<
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = intel
Line 1,358 ⟶ 1,380:
tcl_platform(threaded) = 1
tcl_platform(user) = glennj
tcl_platform(wordSize) = 4</
=={{header|TI-89 BASIC}}==
<
=={{header|TXR}}==
Line 1,395 ⟶ 1,417:
=={{header|UNIX Shell}}==
The getconf command gets the word size, the piped command list gets the endianness , 1 means Little and 0 means Big :
<
Aamrun$ getconf WORD_BIT
32
Line 1,401 ⟶ 1,423:
1
Aamrun$
</syntaxhighlight>
=={{header|Wren}}==
{{trans|C}}
As this information cannot be reliably obtained via Wren CLI, we instead embed a Wren script in a C application and ask the host program to get it for us.
<
class C {
Line 1,414 ⟶ 1,436:
System.print("word size = %(C.wordSize) bits")
System.print("endianness = %(C.endianness)")</
<br>
We now embed this Wren script in the following C program, compile and run it.
<
#include <stdio.h>
#include <string.h>
Line 1,496 ⟶ 1,518:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,512 ⟶ 1,534:
free(script);
return 0;
}</
{{out}}
Line 1,527 ⟶ 1,549:
endian.
<
int A, B;
char C;
Line 1,536 ⟶ 1,558:
Text(0, " endian
");
]</
{{out}}
Line 1,546 ⟶ 1,568:
=={{header|Z80 Assembly}}==
The Z80's word size is 16-bit, and you'd know this ahead of time simply because there aren't any commands that work with values any larger than that. It's also little-endian, but this can be proven without knowing it in advance using a simple store and load test.
<
ld hl,&8000
ld (&C000),hl ;store &8000 into memory.
Line 1,553 ⟶ 1,575:
jr z,LittleEndian ;handle the case where Z80 is little-endian (which it is, so this branch is always taken.)
;else, do whatever you would do to show that the Z80 is big-endian (it isn't, so execution never reaches here.)</
|