Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-05

Does ReallocMem(p,0) always set p to nil?

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vincent Snijders

Hi,

Consider this piece of code:

var
   p: pointer;
begin
   p := getmem(100);
   reallocmem(p,0);
   p := nil;
end.
Do I need to do p:=nil, if I want to be sure that p contains nil?

I saw that both system.SysReAllocMem and cmem.CReAllocMem do this, is size=0, but the docs at
http://lazarus-ccr.sourceforge.net/docs/rtl/system/reallocmem.html don't mention this, so I don't know if I can be trust that is the case for always for all memory managers.

Vincent

Reply by email

josepascual (almudi
to Vincent Snijders

Hi Everyone,

I have compiled hello_eabi_arm (hello world!) with ppcrossarm and -GfSOFT option.

I can run a hello world program with no problem (ldd say me there is not libraries needed)
but if I use dl.pp I received next error (write below), ldd say libdl and libc.so.6 are needed.

any suggestion? how can I discover what file or directory is missing for program,

=================================================================

$ ./hello_eabi_arm

-bash: ./ hello_eabi_arm: No such file or directory

$ gdb hello_eabi_arm

GNU gdb 6.5-debian Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "arm-linux-gnueabi"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) run
Starting program: /tmp/hello_eabi_arm
/bin/bash: /tmp/hello_eabi_arm: No such file or directory /bin/bash: /tmp/hello_eabi_arm: Success

Program exited with code 01.
warning: Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code.
You can't do that without a process to debug.
(gdb)
=================================================================

thanks,
regards

Jose Pascual

Reply by email

Vincent Snijders
to Vincent Snijders: Consider this piece of code: var p: pointer; begin p := getmem(100); reallocmem(p,0); p…
Vincent Snijders wrote 19 lines
Hi, Consider this piece of code: var p: pointer; begin p := getmem(100); reallocmem(p,0); p := nil; end. Do I need to do p:=nil, if I want to be sure that p contains nil? I saw that both system.SysReAllocMem and cmem.CReAllocMem do this, is size=0, but the docs at http://lazarus-ccr.sourceforge.net/docs/rtl/system/reallocmem.html don't mention this, so I don't know if I can be trust that is the case for always for all memory managers.

Tough question apparently. Let's try to word it differently.

After reallocmem(p,0) I observed that p is always nil. Is this an implementation detail (subject to change) or part of the specification of reallocmem?

Vincent

Reply by email

Michael Van Canneyt
to Vincent Snijders
Vincent Snijders wrote 26 lines
Vincent Snijders schreef: > Hi, > > Consider this piece of code: > > var > p: pointer; > begin > p := getmem(100); > reallocmem(p,0); > p := nil; > end. > > Do I need to do p:=nil, if I want to be sure that p contains nil? > > I saw that both system.SysReAllocMem and cmem.CReAllocMem do this, is > size=0, but the docs at > http://lazarus-ccr.sourceforge.net/docs/rtl/system/reallocmem.html don't > mention this, so I don't know if I can be trust that is the case for always > for all memory managers. Tough question apparently. Let's try to word it differently. After reallocmem(p,0) I observed that p is always nil. Is this an implementation detail (subject to change) or part of the specification of reallocmem?

This is part of the specification.

Michael.

Reply by email

Vincent Snijders
to Michael Van Canneyt
Michael Van Canneyt wrote 31 lines
On Mon, 7 May 2007, Vincent Snijders wrote: > Vincent Snijders schreef: >> Hi, >> >> Consider this piece of code: >> >> var >> p: pointer; >> begin >> p := getmem(100); >> reallocmem(p,0); >> p := nil; >> end. >> >> Do I need to do p:=nil, if I want to be sure that p contains nil? >> >> I saw that both system.SysReAllocMem and cmem.CReAllocMem do this, is >> size=0, but the docs at >> http://lazarus-ccr.sourceforge.net/docs/rtl/system/reallocmem.html don't >> mention this, so I don't know if I can be trust that is the case for always >> for all memory managers. > Tough question apparently. Let's try to word it differently. > > After reallocmem(p,0) I observed that p is always nil. Is this an > implementation detail (subject to change) or part of the specification of > reallocmem? This is part of the specification.

Thanks. Can you add this to the documentation?

Vincent

Reply by email