Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.compilers > #3265

Re: C types, was What attributes of a programming language simplify its use?

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 2022-12-11 10:45 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <22-12-022@comp.compilers> (permalink)
References <22-12-001@comp.compilers> <22-12-003@comp.compilers> <22-12-004@comp.compilers> <22-12-019@comp.compilers>

Show all headers | View raw


"marb...@yahoo.co.uk" <marblypup@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/

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-01 14:20 -0800
  Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-02 02:09 -0800
  Re: What attributes of a programming language simplify its use? Thomas Koenig <tkoenig@netcologne.de> - 2022-12-03 10:25 +0000
    Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-03 22:16 +0100
      Re: What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-06 09:56 -0800
        Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-06 12:43 -0800
          Re: What attributes of a programming language simplify its use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2022-12-07 10:14 +0000
        Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-07 12:13 +0100
          Re: What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 17:53 -0800
            Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-08 21:42 +0100
              Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-08 14:44 -0800
                Re: C types, was What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-09 15:01 +0100
              Re: C types, was What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-08 18:35 -0800
              Re: C types, was What attributes of a programming language simplify its use? David Brown <david.brown@hesbynett.no> - 2022-12-09 13:21 +0100
        Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-12 00:00 -0800
      Re: C types, was What attributes of a programming language simplify its use? "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2022-12-09 07:40 -0800
        Re: C types, was What attributes of a programming language simplify its use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2022-12-11 10:45 +0000
        Simple to implement and to use Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-12-11 19:41 +0200
  Re: What attributes of a programming language simplify its use? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-12-03 23:33 +0000
    Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-03 17:15 -0800

csiph-web