Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.mb-net.net!open-news-network.org!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.misc Subject: Re: A good subset of C Date: Mon, 05 May 2014 07:33:27 -0400 Organization: Aioe.org NNTP Server Lines: 70 Message-ID: References: NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.misc:2183 On Mon, 05 May 2014 03:47:01 -0400, James Harris wrote: > In two recent threads we discussed good and bad points about C. Some good > things were mentioned but the focus was mainly on the points that we > would > like to fix. I got to wondering if there could be considered a "good" > subset > of C - i.e. of the whole programming approach including language, > preprocessor, > standard library etc. > > The subset should be much easier to compile than full C but it does not > need to do everything that a programming language should; things could be > added. > > Put another way, if you were designing a new language based on C what > parts of C would you keep in? > It's really a question of how minimal or how primitive do you want that subset to be. It's useful either way, just a question of how useful. I'd say you need an if statement, one loop statement - while(1), break, switch, curly braces, most of C's math and assignment operators, pointers, functions, ability to take addresses of object &, ability to dereference pointers to data and to call functions *, subscript operator for "arrays" [], structs, typedefs, variables, unsigned char, unsigned long. A few preprocessor directives such as: #include, #if, #endif, #ifdef, #define, would be useful. I'd keep hexadecimal and decimal for number representation. There is little need for octal for numeric representations. There is no need for floats. There is no, or not much, need for goto, continue, unions, or an else statement. There is no need for more than two integer types. One is for characters and the other for integers. There is minimal need of the standard libaries, except . You may want a few functions from other library include files such as malloc(), free(), exit(), atexit(). While you need "addressof" &, you generally don't need "sizeof" sizeof(), or the "typeof" and "alignof" operations internal to most C compilers. You can definately forget about any GNU C extension. You can eliminate unary operators, pre-dec/increment, most use of the comma operator, the conditional ?: operator, etc. Some of C's operators are redundant or can be expressed using the others, which eliminates the need for them, especially the numerous assignment operators. E.g., 'a+=3' becomes 'a=a+3', 'a->b' becomes '(*a).b', and 'a[b]' becomes '*((a)+(b))'. (So, that's like a lot of them gone ...) Of course, parenthesis just clutter up the code, so, fix that. ;-) For a truly minimalist situation, you can get by without switch, structs, typedefs, malloc, free, exit, atexit. However, the language becomes really annoying without them. Everything must be declared to be allocated, and *everything* is pointer based, i.e., to emulate structs or arrays. Not having a switch means many if statements, etc. You could consider eliminating character escape sequences, e.g., '\n' '\"' etc. That will simply strings. However, you'll have to use 'putc(0x13)' to do '\n' etc. Eliminating an escaped quote will eliminate some parsing issues ... "quote\"escaped" You could consider eliminating 'void' and 'void *'. I.e., go back to using character pointers. Rod Pemberton