Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!husc6!panda!genrad!decvax!decwrl!pyramid!pesnta!hplabs!sdcrdcf!trwrb!scgvaxd!felix!peregrine!mike From: mike@peregrine.UUCP Newsgroups: net.lang.c Subject: boolean datatype Message-ID: <393@peregrine.UUCP> Date: Sat, 31-May-86 21:41:11 EDT Article-I.D.: peregrin.393 Posted: Sat May 31 21:41:11 1986 Date-Received: Tue, 3-Jun-86 23:57:35 EDT References: <5498@alice.uUCp> <1462@mmintl.UUCP> <852@bentley.UUCP> <1126@whuxl.UUCP> Reply-To: mike@peregrine.UUCP (Mike Wexler) Organization: Peregrine Systems, Irvine, Ca Lines: 52 Summary: why to booleans would be nice This is not a proposal to change the ANSI standard. This is just some ideas some possible ways of improving C. >Re: builtin bool type >>I'm not sure why not. Assuming all the implicit int/bool conversions stay, >>I think the only problems are (a) it isn't really necessary, and (b) it adds >>a new reserved word (breaking any programs that use "typedef int bool"!). > >(a) is the biggie. Why add bool when "typedef enum { FALSE, TRUE } bool;" >works fine? (Relying on ANSI C's treatment of enums as real ints) So that the built in statements can use them. ... int n,get_number(); n=7; if (n=get_number()) printf("got 7\n"); /* should have been == */ ... This is an example of a place where a C compiler with boolean types would catch a mistake. ... bool flag,get_yes_or_no(); if (flag=get_yes_or_no()) printf("got yes\n"); /* no mistake */ ... This is an exmaple of a place where most of the idea for finding mistaken assignments would fail. One possible way to put this in C would be to do the conversion from int to bool(if the integer is not equal to zero then make it true else make it false) and generate a warning. This would add a new reserved word and would break programs that used bool as an identifier. At some future time the warning could become an error message. Another feature I would like to have is a range data type. I don't know of a good syntax for putting this in C but it would be nice to use in programs where are know the possible values of a number but would like the compiler to figure out an efficient sized slot to put it in. ... range hour:1..12; /* create a variable named hour that can vary from */ /* 1 through 12 */ typedef range DAY:1..366; DAY day1,day2; hour+=2; day1=day2+100; } I will let other people argue about how to index an array by a range. -- Mike Wexler Email address:(trwrb|scgvaxd)!felix!peregrine!mike Tel Co. address: (714)855-3923 ;-) Internet address: ucivax@ucbvax.BERKELY.EDU!ucivax%felix!mike@peregrine :-(