From: timm@xongmao.ncsa.uiuc.edu (Tim McClarren)
Newsgroups: comp.programming,comp.lang.c,comp.lang.pascal,comp.lang.objective-c
Subject: Re: NO NUMBERS! (or even SHORT INTS!)
Date: 29 Sep 92 19:39:39 GMT
Article-I.D.: xongmao.timm.717795579
Organization: University of Illinois at Urbana

jfr@RedBrick.COM () writes:

>The problem I started thinking about is WHY IN THE WORLD WOULD ANYONE
>USE SHORT INTS IN A PROGRAM, particularly one done for a workstation-level
>machine (i.e., large memory model, etc).

I agree...I once wrote on our "communal whiteboard" here 
"UNSIGNED LONG <EVERYTHING>".  I only make things of a different
type when they need to be (ie, something needs to be negative).

>In a related conversation, someone mentioned that many organizations have
>coding standards that let them redefine the size of ints to keep this
>from happening.  For instance use int1, int2 and int4 as typedefs and you 
>can make them whatever you want.  This is where the thought struck me that
>makes me curious to get other peoples' opinion on.  Why would you EVER
>use NUMBERS in a program.  Except in TWO places: inside quoted strings
>and on the right side of #defs (or the equivalent depending on the
>language).  There is no justification for using a number in a variable
>name or typedef or whatever.  The above example should be vsi, si and li 
>or shint, regint, lngint or something like that.  JUST NAMES, NOT NUMBERS.
>Why?  Because using numbers causes a confusion in the event that you 
>decide to change the platform or the concept.  It is fair to say that
>a lngint must be equal to or longer than a regint, but I contend it is
>erroneous and misleading to say that an int4 must be EQUAL TO or longer
>than an int2.  Longer than, maybe, but EQUAL TO?  That is just wrong.
>In fact, int4 and int2, by normal thought processes, expresses an exact
>2:1 relationship.  And the fact that I can change that in a hidden way
>does NOT make things clearer, it makes things muddier.

I don't agree with this at all however...take the following:

typedef char              char8;
typedef unsigned char     uchar8;
typedef char              int8;
typedef unsigned char     uint8;
typedef short int         int16;
typedef unsigned short int uint16;
typedef long int          int32;
typedef unsigned long int uint32;
typedef int               intn;
typedef unsigned int      uintn;
typedef float             float32;
typedef double            float64;

This is from a header file from HDF (Hierarchical Data Format), which
is a fairly widely used cross-platform file format used for storing
large amounts of scientific data.  The above typedef's are for an
HP-9000, and there are other sets of typedef's for about a dozen
other platforms.  You'll notice the "intn" in the middle.  This is
only used when you REALLY don't care how long the int is (very seldom).
Can you think of another BETTER way to do this such that the same code
can be used on all of the following platforms AND produce the exact
same files that can be moved transparently from one to the other?

        Platform        Machine Type
        --------        ------------
        Sun-4           SUN
        Cray-2          UNICOS
        Cray-Y/MP       UNICOS
        Convex          CONVEX
        SGI Iris 4D     IRIS4
        IBM RS/6000     IBM6000
        DECstation 3100 MIPSEL
        DECstation 5000 MIPSEL
        Vax/VMS         VMS
        HP 9000         HP9000
		NeXT			NEXT
        Macintosh       MAC
        IBM PC/clone    PC

Oh, and don't forget, the VAX and PC's have wierd byte ordering :o).

-- 
Tim McClarren     | "...a bajillion brilliant Jobsian lithium licks."
timm@ncsa.uiuc.edu|
(217)244-0015     |
Newsgroups: comp.programming