cc: [email protected] Subject: Re: [ast-developers] [rfe] typeset -B to define a (C99-like) <stdbool.h> datatype --------
> I'd like to propose a new typeset option to define a new boolean > datatype which works like C99 "bool" datatype defined in <stdbool.h>, > e.g. typeset -B bl; integer i; (( bl=true, i=bl )) ; print "$bl\n$i" > prints $'true\n1\n' > > The purpose is to have a (memory space-)efficient way to define a > boolean datatype in shell scripts which can be used with arithmetic > expressions and arrays and works exactly like the "bool" datatype > defined in <stdbool.h>. > I know it is possible to define such a datatype with typeset -T right > now, however we'd like to use such this datatype primarily in very > large arrays, in which case usage of user-defined types becomes a > memory usage nightmare. That's why "hardcoded" support via typeset -B > would be beneficial - it could use bitfields instead of a nval > structure and use two bits to represent a typeset -B array entry - one > bit is used for the value and a 2nd bit defines whether the array > entry is actually defined or not so that sparse bitfield arrays are > possible. This should be at least 80 times (sizeof(struct > nval)==5*sizeof(void*) vs 2 bits) more space efficient than any > possible implementation via typeset -T. > > Irek > _______________________________________________ > ast-developers mailing list > [email protected] > http://lists.research.att.com/mailman/listinfo/ast-developers > The shell already has enumeration types. Maybe I should look for an efficient way to store an indexed array of enumeration types. The you can do enum Bool=(true false) Bool x=(true false false true false) to create an indexed array of 5 elements. David Korn [email protected] _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
