This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Help with malloc
In other words, it just so happens that the address space used when you alloc that much is >2GB, so the first bit is set which appears as a negative number if you cast it to a signed int. It is a valid pointer, so just use it.
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Andrew Bell
Sent: Friday, October 10, 2008 1:34 PM
To: Vardhan, Sundara (GE Infra, Energy)
Cc: gcc-help@gcc.gnu.org
Subject: Re: Help with malloc
On Fri, Oct 10, 2008 at 1:30 PM, Vardhan, Sundara (GE Infra, Energy)
<sundara.vardhan@ge.com> wrote:
> Hi All
>
> Desperate: Do not know if this is the right forum for this
> question. Using gcc 4.1.1 on Red Hat Linux, I keep getting negative
> pointer value when I try to allocate more than 128000 bytest using
> malloc(). Works fine if the value is less than 128000. Any ideas why
> this happens. I would very much appreciate your help and input.
RETURN VALUE
For calloc() and malloc(), the value returned is a pointer to the
allocated memory, which is suitably aligned for any kind of variable,
or NULL if the request fails.
--
Andrew Bell
andrew.bell.ia@gmail.com