C integral types [was Re: Semi-OT: Why Kids Can't use Computers] (fwd)
D. Hugh Redelmeier
hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Thu Aug 15 17:54:31 UTC 2013
[A DCB message to the TLUG list. I'm forwarding because the list discards
his mail.]
---------- Forwarded message ----------
From: David Collier-Brown <davec-b-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org>
To: tlug-lxSQFCZeNF4 at public.gmane.org
Cc: D. Hugh Redelmeier <hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org>
Date: Thu, 15 Aug 2013 13:25:03 -0400
Subject: Re: [TLUG]: C integral types [was Re: Semi-OT: Why Kids Can't use
Computers]
Reply-To: davecb-0XdUWXLQalXR7s880joybQ at public.gmane.org
On 08/15/2013 09:40 AM, D. Hugh Redelmeier wrote:
> | From: James Knott <james.knott-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org>
>
> | I had to be careful, due
> | to differences in integer size.
>
> That is the nature of C. If you want to write portable code, you have
> to be careful about the width of integral types. Sadly, the
> language gives you inhumane tools for this.
>
> Since your experience, the C Standards have provided headers that let
> you select an integral type with a desired number of bits. But how
> does anyone know, for most variables, how many bits they need?
>
> Ignoring that, you kind of know that the following is a monotonically
> non-decreasingly wide sequence of types:
>
> signed char
> short
> int
> long
> long long
> intmaxt_t /* defined in inttypes.h */
>
> Then there are unsigned variants. And plain char might be signed or
> not.
>
> When I first used C, the only char and int existed. All these others
> were accreted over time.
>
> Pascal was much better. You can use subrange types which let you
> specifiy bounds for your integral variables (like array bounds, but
> for integers). Aside from the fact that the bounds had to be known
> at compile time, it was quite helpful.
>
> I wrote a lot of code in Sue, an extended subset of Pascal that didn't
> even let you declare an integer variable: you always had to use a
> subrange.
> --
> The Toronto Linux Users Group. Meetings: http://gtalug.org/
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
>
Previous to C, and in languages from the same broad family,
you had "words" in B, and specific numbers of digits and bits in PL/1.
The C authors reacted strongly to "fixed binary 71" and introduced
types that were less strongly tied to machine-word sizes.
I liked "fixed decimal 6", but hated "fixed binary 71", so C was a step
up for me. It's too bad their idea of fixed decimal wasn't Sue's!
--dave
--
David Collier-Brown, | Always do right. This will gratify
System Programmer and Author | some people and astonish the rest
davecb-0XdUWXLQalXR7s880joybQ at public.gmane.org | -- Mark Twain
(416) 223-8968
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list