Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: anton@mips.complang.tuwien.ac.at (Anton Ertl) Newsgroups: comp.compilers Subject: Re: C types, was What attributes of a programming language simplify its use? Date: Sun, 11 Dec 2022 10:45:08 GMT Organization: Institut fuer Computersprachen, Technische Universitaet Wien Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-12-022@comp.compilers> References: <22-12-001@comp.compilers> <22-12-003@comp.compilers> <22-12-004@comp.compilers> <22-12-019@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="57124"; mail-complaints-to="abuse@iecc.com" Keywords: types, history Posted-Date: 11 Dec 2022 13:13:07 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3265 "marb...@yahoo.co.uk" writes: > From nearly 40 years >of C programming, I've concluded that having "int" be the "natural" size of >integer is more of a liability than an asset.) I have also been programming in C, but also in Forth since the 1980s. C has the well-known integer type zoo, but evolved from B, which had only a single type (the machine word, which became "int" in C). On the integer side Forth has only cells (machine words) and double-cells, and, in memory, characters (bytes), which are loaded and processed as cells (like chars in C are promoted to ints). My experience is that portability bugs are very rare in Forth code, while they are much more common in C code. Not only is there a zoo of integer types in C, there are also additional integer types (off_t, uid_t, time_t, etc.) that are mapped to different more basic integer types on different platforms; and there are library functions like printf(), abs/labs/llabs() etc. where you have to decide on one of a few integer types, but if the type at hand is not among them, you need to use some cumbersome non-C machinery like configure to select the code. By contrast, in Forth most integers are passed as cells. When you pass it as double-cell, you also pass it on a different platform (with different cell width) as double-cell, so once you debug the program on one machine, it almost always works on a machine with a different cell size. However, there is one discipline you have to observe: For address computations you have to use the cell-size-agnostic scaling word CELLS rather than making use of the knowledge of the cell size on the platform you are testing on (Forth code from the 16-bit era, before CELLS was introduced, uses 2* instead, and is not portable to systems with wider cells). - anton -- M. Anton Ertl anton@mips.complang.tuwien.ac.at http://www.complang.tuwien.ac.at/anton/