Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!snorkelwacker.mit.edu!hsdndev!cmcl2!adm!news From: ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu (Josep Sau B.) Newsgroups: comp.lang.pascal Subject: Type cast byte/word in a record Message-ID: <26668@adm.brl.mil> Date: 25 Apr 91 08:17:15 GMT Sender: news@adm.brl.mil Lines: 28 Alan mead asked about accessing fields in a record as bytes or as words... Well, the cleanest way would be using a variant record, if know in advance that words will be always aligned in odd or in even bytes, like: Ambiguous: RECORD CASE BOOLEAN OF FALSE :( ByteArr : ARRAY 1..Siz! OF BYTE); TRUE :( WordArr : ARRAY 1..Siz DIV 2! OF WORD); END; But if you need to access to words aligned to any byte, like Mem and MemW allow, you can simply do a typecast everytime you need to access (read, assign...) two bytes as a word. Example: Word(Ambiguous.ByteArr1!) accesses bytes 1 and 2 as a word Word(Ambiguous.ByteArr2!) accesses bytes 2 and 3 as a word ... You have to bother about the order of least and most signifiant byte in a word, which is 80x8x implementation dependent. --Josep Sau