On Mon, Dec 10, 2012 at 7:39 PM, David Korn <[email protected]> wrote: > 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.
I have two concerns: 1. ksh -c 'enum bool=(false true) ; bool -a bar ; integer i=5 ; bar[3]=true ; print $(( i+bar[3] ))' prints 5, not 6. There seems to be a bug. 2. The request is to have the bool type enabled by default, as the bool datatype is a mandatory part of C99. Irek _______________________________________________ ast-developers mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-developers
