Re: [AD] mode-list updates. |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Tue, 2 Oct 2001, Martijn Versteegh wrote:
> On Tue, Oct 02, 2001 at 02:17:26PM +0200, Henrik Stokseth wrote:
> >On Tuesday 02 October 2001 02:50, Peter Wang wrote:
> >
> >> Btw, in both modesel.c and bgfxapi.cpp, `realloc' is being used
> >> incorrectly.
> >
> >Oh really? i think you are mistaken here, unless you can convince me
> >otherwise.
> >
> >realloc has some cool features. for example if ptr is NULL it works
> >equivalent to malloc and if size is 0 it works equivalent to free.
> >
> AFAIK this is not true for every compiler out there.
>
> it is for gcc, and I think it is for msvc, but I'm not sure if it's
> in the ansi c specs.
realloc(NULL, size) is good according to ISO/ANSI C and means the same as
malloc(size)
realloc(ptr, 0) is not any special (read: "there is no notice regarding
that in specs") according to ISO/ANSI C. You can't be sure what will
happen in this case. Stupid realloc() implementation could have malloc(0)
return zero-sized block of memory aligned to 4 KB (for example :-).
Following information is from various libc implementations (just for
completness):
IRIX 6.5
If size is zero, the storage associated with ptr is freed and realloc
returns the same result as does malloc(0).
SunOS 5.8
If size is 0 and ptr is not a null pointer, the space pointed to is
made available for further allocation
GNU glibc-2.2.3
if size is equal to zero, the call is equivalent to free(ptr).
Have a nice day.
Stepan Roh