Subject: variant records and packed arrays To: gpc@hut.fi Date: Sun, 16 Nov 1997 13:12:13 +0100 (MET) From: "Christian Bockermann" chris@bockermann.ping.de X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Length: 1971
Hello everyone !
I have a little question concerning variant records and packed arrays. In schoolwe wrote a little program with a declaration part like this :
var x : RECORD CASE Boolean OF False :( rec:Record name : String[3]; number : integer; end); true :( field:packed array [0..47] of boolean ); end;
The consequence was that the record (rec) and the array (field) were settled in the same area in memory. So this area could be interpreted as a field of bits or a record of a string an an integer variable. This was done on a Mac with Think Pascal :-(, but I'm unable to do something like this on my Linux-Box. The rest of my program looks like this :
procedure print_out; var i :integer; begin write('binary decoding :'); for i:=0 to 47 do begin if x.field[i] then write('1') else write('0'); if i MOD 8 = 7 then write (' '); end; end;
begin x.rec.name:='AB'; x.rec.number:=9; writeln(x.rec.name, x.rec.number); print_out; end.
So I expected the output to be 1.) the binary decoding of the length of the string, like 00000010 2,3.) binary decoding of the ascii-code of the characters in the string, like 01000001 01000010 4.) some 8 random bits 01010101 or something similar... 5.) the 16-bit decoding of the integer variable, like 00000000 00001001
The output I get is : 1.) 2.) 3.) 4.) 5.) 6.) binary decoding :00000000 00000000 00000000 00000001 10000000 00000000
Does anybody know, what I did wrong ? Is it possible in another way to access and change some bits of a string of any other variable with the use of GPC ?
If anybody can help ... THANKS a lot !!
-- Chris
e-mail > chris@bockermann.ping.de ____________________________________ (subject "send pgp-key" for pgp-key)