Help with malloc
Vardhan, Sundara (GE Infra, Energy)
sundara.vardhan@ge.com
Wed Oct 15 18:49:00 GMT 2008
Hi All
Thanks very much for your very valid inputs. I did as suggested and
instead of checking to see if the pointer returned -ve (this was legacy
code not mine :-)), I changed it to check for null and continued to use
this pointer and all worked fine so far.
Thanks much for the advice.
With Regards
Vardhan
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Austin, Alex
Sent: Friday, October 10, 2008 2:58 PM
To: 'Andrew Bell'; Vardhan, Sundara (GE Infra, Energy)
Cc: gcc-help@gcc.gnu.org
Subject: 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
More information about the Gcc-help
mailing list