Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!brl-adm!brl-smoke!rgh%inmet.uucp@BRL.Arpa From: rgh%inmet.uucp@BRL.Arpa Newsgroups: net.lang.c Subject: boolean datatype Message-ID: <1267@brl-smoke.ARPA> Date: Tue, 10-Jun-86 20:46:46 EDT Article-I.D.: brl-smok.1267 Posted: Tue Jun 10 20:46:46 1986 Date-Received: Fri, 20-Jun-86 04:27:27 EDT Sender: news@brl-smoke.ARPA Lines: 60 Return-Path: Redistributed: Xerox-Info-C^.x@XEROX.ARPA Received: from BRL-AOS.ARPA by Xerox.COM ; 02 JUN 86 16:42:38 PDT Received: from brl-smoke.arpa by AOS.BRL.ARPA id a015997; 2 Jun 86 17:28 EDT Received: from USENET by SMOKE.BRL.ARPA id a005687; 2 Jun 86 17:01 EDT Newsgroups: net.lang.c Message-ID: <393@peregrine.UUCP> 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 :-(