delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/09/12:13:46

Date: Sun, 09 Oct 1994 10:08:26 EDT
From: "B.J. Herbison" <bj AT herbison DOT com>
Organization: Herbison Consulting, Leominster, MA 01453-523218 +1 508 534-1050
To: "Frederick W. Reimer" <fwreimer AT crl DOT com>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: djgpp and the 386SX

On Fri, 7 Oct 1994 17:49:41 -0700 (PDT), "Frederick W. Reimer" <fwreimer AT crl DOT com> wrote:

> As far as Unix programs and such are concerned, what's wrong with 
> assuming that the size of an int is the same as the size of a pointer?  
> This is almost a given in the C programming world, or at least is should 
> be.

The problem with assuming that ints are the same length as pointers
is that the code won't work when the assumption doesn't hold.  There
is no necessary reason for a compiler to be implented in that manner.

At work I use machines where the cc has 32-bit ints and 64-bit pointers.
There were lots of problems porting bogus code, but the solutions were
simple, and after we fixed (yes, fixed) the programs the resulting code
would be much easier to port to other systems.

>  I conceed that assuming the length of any pointer is bad programming 
> practice -- and, in general, assuming the byte ordering of any "pointer" 
> or "int" type is bad programming practice; but for those programs (device 
> drivers / kernels) that require a low-level understanding of the 
> architecure[sp] that it is running on, what else are the programs to 
> assume?

Assume that the size of an int is sizeof(int), the size of a pointer to
an int is sizeof(int *), and so on.  If you want to store multiple types
in the same location, learn about the `union' construct.

> There is a certain level of non-portability in every program, it 
> just depends on what the program is designed to accomplish as to how 
> non-portable it is.

Of course.  A program written in C is very hard to port to a system
without a C compiler.  However, if you write a program for a
well-defined environment (e.g., ANSI C, POSIX), and stick within the
environment, it isn't hard to write a program that is easy to port.
(It does help to have multiple operating systems and compilers to
use when you develop the program, compiling with all warnings enabled
and using lint.)

   						B.J.
-- 
B.J. Herbison           Herbison Consulting         Another Asylum
bj AT herbison DOT com         +1 508 534-1050             18 Drummer Lane
                        42 29 30 N / 071 44 10 W    Leominster, MA  01453  USA

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019