Memory layout of a data structure: Difference between revisions

m
no edit summary
mNo edit summary
Line 357:
RI Ring indicator
)</lang>
 
=={{header|Julia}}==
<pre>
If the nine-pin version of the serial port is as specified above:
 
1 2 3 4 5
6 7 8 9
9 pin
PG Protective ground
TD Transmitted data 3
RD Received data 2
RTS Request to send 7
CTS Clear to send 8
DSR Data set ready 6
SG Signal ground 5
CD Carrier detect 1
+ voltage (testing)
 
We can then make the following code for a new serial port type.
In Julia, a <code>type</code> is a kind of struct or object. To do so, we may convert
an existing base class BitArray type, which is a subtype of Julia's DenseArray:
</pre>
<code Julia>
mutable struct NinePinSerialPort
pins::BitArray
function NinePinSerialPort()
this = new()
pins = BitArray(9)
end
end
 
const CD = 1
const RD = 2
const TD = 3
const SG = 5
const DSR = 6
const RTS = 7
const CTS = 8
 
port = NinePinSerialPort()
 
# Here we test the type's code.
 
println("Port is now at defaults, which are $port")
port[CTS] = true
println("CD pin of port, which is pin $CD, is now $(port[CD])")
println("CTS pin of port, which is pin $CTS, is now $(port[CTS])")
println("port is now: $port")
</lang>
{{output}}
<pre>
Port is now at defaults, which are Bool[false, false, false, false, false, false, false, false, false]
CD pin of port, which is pin 1, is now false
CTS pin of port, which is pin 8, is now true
port is now: Bool[false, false, false, false, false, false, false, true, false]
</pre>
 
=={{header|Kotlin}}==
4,103

edits