Host introspection: Difference between revisions

m
(→‎{{header|Go}}: Put back completely non-portable /proc hack but and some comments)
Line 1:
{{task|Programming environment operations}}
{{omit from|Brlcad}}
{{omit from|E}}
{{omit from|JavaScript}}
{{omit from|Maxima}}
{{omit from|ML/I}}
{{omit from|Openscad}}
{{omit from|TPP}}
{{omit from|Unlambda}}
 
Print the [[wp:Word_size#Word_size_choice|word size]] and [[wp:Endianness|endianness]] of the host machine.
 
See also: [[Variable size/Get]]
 
=={{header|Ada}}==
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
Line 12 ⟶ 22:
Put_Line ("Endianness " & Bit_Order'Image (Default_Bit_Order));
end Host_Introspection;</lang>
 
{{out|Sample output on a Pentium machine:}}
<pre>
Word size 32
Endianness LOW_ORDER_FIRST
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
Line 46 ⟶ 58:
OD;
printf(($"int byte order: "g,", Hex:",16r8dl$,int byte order, BIN abcdi))</lang>
Output{{out}} (Intel i686):
<pre>
states per bit: 2
Line 198 ⟶ 210:
4</lang>
 
In the case of endianness, Erlang's bit syntax by default has a 'native' option which lets you use what is supported natively. As such, there is no function to find endianness. However, one could write one by using bit syntax, setting endianness and then comparing to the native format:
As such, there is no function to find endianness.
However, one could write one by using bit syntax, setting endianness and then comparing to the native format:
 
<lang erlang>1> <<1:4/native-unit:8>>.
Line 387 ⟶ 401:
println "endianness: ${System.getProperty('sun.cpu.endian')}"</lang>
 
{{out}}
Output:
<pre>word size: 64
endianness: little</pre>
Line 457 ⟶ 471:
$SystemWordLength "bits"</lang>
 
{{out}} x86 Output:
<pre>
Little endian
Line 488 ⟶ 502:
</lang>
 
{{out}}
Output:
<pre> octave:128> computer
x86_64-unknown-linux-gnu
octave:129> endian
endian = little</pre>
 
 
 
Line 510 ⟶ 523:
END Host.</lang>
 
Output{{out}} (on an x86):
<pre>
Word Size: 32
Endianness: Little
</pre>
'''Bold text'''
 
=={{header|NetRexx}}==
Line 645 ⟶ 657:
writeln('This host is little endian.');
end.</lang>
{{out}}
Output:
<pre>
>: ./HostIntrospection
Line 656 ⟶ 668:
<lang perl>use Config;
print "UV size: $Config{uvsize}, byte order: $Config{byteorder}\n";</lang>
{{out}}
Example output:
<pre>
UV size: 4, byte order: 1234
Line 671 ⟶ 683:
}
say "UV size: $size, byte order: $order ($end-endian)";</lang>
{{out}}
Example outputs:
<pre>
UV size: 4, byte order: 1234 (little-endian)
Line 704 ⟶ 716:
(2 "Big endian")
(T "Bad EI_DATA") ) ) )</lang>
{{out}}
Output:
<pre>64 bits
Little endian</pre>
Line 722 ⟶ 734:
end details;
</lang>
{{out}}
output:
<pre>
word size= 32
Line 736 ⟶ 748:
Write-Host Big-Endian
}</lang>
Note that endianness is essentially a moot point with PowerShell, as there is only a Windows implementation currently and current Windows versions don't run on big-endian systems. But in theory this check should work.
as there is only a Windows implementation currently
and current Windows versions don't run on big-endian systems.
But in theory this check should work.
 
=={{header|PureBasic}}==
<lang PureBasic>Enumeration
Line 840 ⟶ 856:
 
=={{header|Scala}}==
[[Category:Scala Implementations]]
{{libheader|Scala}}<lang Scala>import java.nio.ByteOrder
 
Line 889 ⟶ 904:
<lang slate>inform: 'Endianness: ' ; Platform current endianness.
inform: 'Word Size: ' ; (Platform current bytesPerWord * 8) printString.</lang>
{{out}}
Output:
<pre>
Endianness: LittleEndian
Line 929 ⟶ 944:
]</lang>
 
{{out}}
Output:
<pre>
4
Little endian
</pre>
 
{{omit from|Brlcad}}
{{omit from|E}}
{{omit from|JavaScript}}
{{omit from|Maxima}}
{{omit from|ML/I}}
{{omit from|Openscad}}
{{omit from|TPP}}
{{omit from|Unlambda}}
Anonymous user