Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Newbie need help

 [1/3] from: bruno:fine:wanadoo at: 9-Oct-2002 17:58

Hello i am newbie and i need some help. i want to translate this sample from C to Rebol : union uniontest{ unsigned char data; struct{ unsigned char c:3; unsigned char x:5; } dum; }; int main(int argc, char* argv[]) { uniontest dummy;; printf("%x",(char)dummy.dum.c); printf("\r\n%x",dummy.dum.x); return 0; } How could i use this kind of union with Rebol ? Thx for your help

 [2/3] from: greggirwin::mindspring::com at: 10-Oct-2002 11:18

Hi Bruno, << How could i use this kind of union with Rebol ? >> What is the goal you really want to achieve? I.e. rather than trying to figure out how to model something like a C union in REBOL, what is the problem you want to solve, stated in "human" terms? Coercing/casting values, formatting data, etc. --Gregg

 [3/3] from: rotenca:telvia:it at: 10-Oct-2002 22:03

Hi, Bruno you could simulate unions with object and functions. This example put in c first three bits and in x the last five bits union-c: context [ data: none c: does [to integer! data / 32] x: does [to integer! data and 31] ] dum: make union-c [] dum/data: #"a" print [dum/data dum/c dum/x]; = a 3 1 dum/data: #"*" print [dum/data dum/c dum/x];==* 1 10 --- Ciao Romano