On 11/12/2013 10:19 AM, Martin Schreiber wrote: > > If it's really bit packed you might get numerical values that require > rather complex handling by the compiler: > > record tr > x1: int64: 2; > Invalid because int64 is defined as -800000000000..7fffffffffffffff which does > not fit in 2 bits. > > That is not the idea. But:
r.x1= 0 => bits = 0, 0 r.x1= 1 => bits = 0, 1 r.x1= -1 => bits = 1,1 r.x1= -2 => bits = 1, 0 other values are truncated accordingly (see below) On the contrary the base type needs to provide at least as many bits as given after the ":" (otherwise you could never define fields with less than 8 bits). Do you intend to provide a syntax to define bit fields with more bits than any integer base type. This in fact would be intersting but would need you to provide an arbitrary precision integer arithmetic in the RTL. Doable but an "interesting" Task :-) . The purpose (e.g. in C) of providing a base type with the bit-number restricted field is that when doing calculations with such variables they are handled _as_if_ they had the base type (which is necessary because there is no "natural" type for them to determine the way calculations are to be executed) Thus when x1 is used in a calculation, it needs to be (sign) extended to 64 bit and the result of the operation has (at least) 64 significant bits, which need to be respected with the next operation done on tat result. e.g. b: byte; r: tr; r.x1 := -1; b := x1>>16; (a 64 bit type var combined with a 8 bit type const forces 64 bit arithmetic and result), storing a 64 bit value in an (unsigned) 8 bit value drops the upper 56 bits. results in $FF -Michael ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk