Create an object at a given address: Difference between revisions
Content added Content deleted
(Create Perl 6 example) |
|||
Line 569: | Line 569: | ||
$struct.foo++; # 42 |
$struct.foo++; # 42 |
||
# Check that we're actually updating the memory |
|||
# run some tests. Try to be archecture indenpdent |
|||
use Test; |
use Test; |
||
# look at the bytes directly to verify we've written to memory. Don't be too exact, as |
|||
# 42 should be in first or second byte, depending on endianess |
|||
# the positions may vary on different platforms depending on endianess and record alignment. |
|||
⚫ | |||
my $rec-size = nativesizeof(SampleObject); |
|||
# the exact position of the second field may depend on record alignment. |
|||
my uint8 @bytes-written = (0 ..^ $rec-size).map(-> $i {$base-p[64 + $i]}).grep: * > 0; |
|||
# fair chance it's +2 (unpacked) +4 (32 bit) or +8 (64 bit) |
|||
is ($base-p[64+2] || $base-p[64+4] || $base-p[64+8]), 99, 'object second field'; |
|||
# first field 'foo' (amount is small enough to fit in one byte) |
|||
⚫ | |||
# second field 'bar' |
|||
is @bytes-written[1], 99, 'object second field'; |
|||
# tidy up |
# tidy up |
||
Line 590: | Line 594: | ||
1..2 |
1..2 |
||
</pre> |
</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Phix does not support creation of a "language object" at a specific address, but you can peek and poke bytes, words, dwords and qwords |
Phix does not support creation of a "language object" at a specific address, but you can peek and poke bytes, words, dwords and qwords |