Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: peter@nmti.com (Peter da Silva)
Subject: Re: help, malloc 32 vs malloc 64
Date: Mon, 17 Oct 1994 16:53:57 GMT	[thread overview]
Message-ID: <id.RVXD1.W0L@nmti.com> (raw)
In-Reply-To: 37om6o$s79@csugrad.cs.vt.edu

In article <37om6o$s79@csugrad.cs.vt.edu>,
Teak 'Teakster' Min <teak@csugrad.cs.vt.edu> wrote:
> Problem:  I am working on a DEC Alpha using OSF/1.  I need to know
> if there is anyway to #define an int in C to a long.  What I am 
> having problems is that when I malloc and I get a memory location, 
> the address is assigned to a pointer of type int which is 32bit but
> the system gives back an address with is greater than 32bit address.

No, a pointer to an integer is 64 bits wide. An integer is 32 bits wide.
It is not possible in general to assign a pointer to an integer. For
about 8-10 years the majority of high performance platforms did have
an integer that was the same size as a pointer, and people have written
code that depends on this implementation detail, but the language itself
does not guarantee it.

The fix is to change your code so it no longer tries to store a pointer
in an integer.

> I know that OSF is a 64 bit architecture.  What I need to know is
> how to compile my program which will use only address in the
> 32bit range OR set on option that will make int larger than 32bit.

Neither is possible or desirable.

> This program (or I should say environment) is compiled using both
> cc and gcc.  I was TOLD that c was a portable code, was I lied to?

If you were told that this program was portable, you were lied to.

If you were told that it is possible to write portable code in C, that
is the truth. It is possible to write portable code in C, however that
doesn't imply that all code written in C is portable.

> Why not change all my int to long? Well this program has over a
> hundred if not more files in several directories and I wish not
> to go in all those files and change int to long.

That's good, because that's not what you need to do. What you need to
do is fix the broken code that assumes that you can store a pointer in
an integer. If you don't wish to do that, there's no doubt many people
on the net who will be willing to do it for you for a reasonable fee.
-- 
Peter da Silva                                            `-_-'
Network Management Technology Incorporated                 'U`
1601 Industrial Blvd.     Sugar Land, TX  77478  USA
+1 713 274 5180                       "Hast Du heute schon Deinen Wolf umarmt?"


  parent reply	other threads:[~1994-10-17 16:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-15 13:41 help, malloc 32 vs malloc 64 Teak 'Teakster' Min
1994-10-15 23:38 ` Dirk Grunwald
1994-10-17 16:53 ` Peter da Silva [this message]
1994-10-17 23:18   ` Dirk Grunwald
1994-10-18 14:28     ` Peter da Silva
1994-10-18 17:41     ` oberman
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox