Re: [fpc-pascal] pointer type as procedure arg

2024-12-30 Thread Florian Klämpfl via fpc-pascal
> Am 30.12.2024 um 12:00 schrieb Mattias Gaertner via fpc-pascal > : > > Hi, > > Are anonymous (aka local) pointer types allowed in procedure arguments in any > mode? I am not aware of. > > procedure Run(p: ^word); > begin > end; > > I found that the fcl-passrc parser has a test to allow

[fpc-pascal] pointer type as procedure arg

2024-12-30 Thread Mattias Gaertner via fpc-pascal
Hi, Are anonymous (aka local) pointer types allowed in procedure arguments in any mode? procedure Run(p: ^word); begin end; I found that the fcl-passrc parser has a test to allow it and I'm wondering if this is by design or a bug. Mattias ___ fpc

Re: [fpc-pascal] Pointer question

2023-08-11 Thread Hairy Pixels via fpc-pascal
> On Aug 10, 2023, at 11:37 PM, Michael Van Canneyt via fpc-pascal > wrote: > > This is a very dirty trick to get the offset of a field in a record. > > Note that you're not dereferencing a type but a variable of type TAlignCheck > located > at memory address zero. The address of w (this is

Re: [fpc-pascal] Pointer question

2023-08-11 Thread Nikolay Nikolov via fpc-pascal
On 8/11/23 01:23, Hairy Pixels via fpc-pascal wrote: On Aug 10, 2023, at 2:18 PM, Michael Van Canneyt via fpc-pascal wrote: https://www.freepascal.org/docs-html/current/ref/refse15.html#x42-620003.4 This document doesn't really do a great enumerating all the operators so I'm not sure if t

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Michael Van Canneyt via fpc-pascal
On Thu, 10 Aug 2023, Hairy Pixels via fpc-pascal wrote: On Aug 10, 2023, at 4:23 PM, Hairy Pixels wrote: // 4) subscript (inc and dereference in one step) v := i[1]; #4 was not in the list for example so I wonder what others exist. I found another one in the typinfo.pp unit. What do

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Hairy Pixels via fpc-pascal
> On Aug 10, 2023, at 4:23 PM, Hairy Pixels wrote: > > // 4) subscript (inc and dereference in one step) > v := i[1]; > > > #4 was not in the list for example so I wonder what others exist. I found another one in the typinfo.pp unit. What does, 1) taking the address of a type (@TAlignChec

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Hairy Pixels via fpc-pascal
> On Aug 10, 2023, at 2:18 PM, Michael Van Canneyt via fpc-pascal > wrote: > > https://www.freepascal.org/docs-html/current/ref/refse15.html#x42-620003.4 This document doesn't really do a great enumerating all the operators so I'm not sure if the list is complete. I think the list is: var

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Michael Van Canneyt via fpc-pascal
On Thu, 10 Aug 2023, Hairy Pixels via fpc-pascal wrote: On Aug 10, 2023, at 10:49 AM, Sven Barth via fpc-pascal wrote: Then you simply aren't using them often enough. E.g. the RTTI internal code is full of them and additional typecasts would simply muddle up otherwise relatively clear

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Hairy Pixels via fpc-pascal
> On Aug 10, 2023, at 10:49 AM, Sven Barth via fpc-pascal > wrote: > > Then you simply aren't using them often enough. E.g. the RTTI internal code > is full of them and additional typecasts would simply muddle up otherwise > relatively clear code. > Here's a question, what is the full li

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Sven Barth via fpc-pascal
Hairy Pixels via fpc-pascal schrieb am Do., 10. Aug. 2023, 18:30: > > > > On Aug 10, 2023, at 5:43 AM, Bernd Oppolzer via fpc-pascal < > fpc-pascal@lists.freepascal.org> wrote: > > > > PTRADD (p, i) - p is type ANYPTR, i is integer, result is of type ANYPTR > > PTRDIFF (p1, p2) - two pointers, th

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Hairy Pixels via fpc-pascal
> On Aug 10, 2023, at 5:43 AM, Bernd Oppolzer via fpc-pascal > wrote: > > PTRADD (p, i) - p is type ANYPTR, i is integer, result is of type ANYPTR > PTRDIFF (p1, p2) - two pointers, the result is integer > ANYPTR is a predefined type, compatible with every (typed pointer) > ADDR (x) is a fun

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Hairy Pixels via fpc-pascal
> On Aug 9, 2023, at 4:37 PM, Tomas Hajny via fpc-pascal > wrote: > > No, the offset is not a memory address but just a number of bytes (which is > also the reason why you cannot add the pointers together, but you can add a > number to a pointer. As an example, you could use this operation

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Bernd Oppolzer via fpc-pascal
FWIW, when I added similar functionality to my Stanford Pascal compiler, I chose not to allow arithmetic of pointers, but instead I added some functions: PTRADD (p, i) - p is type ANYPTR, i is integer, result is of type ANYPTR PTRDIFF (p1, p2) - two pointers, the result is integer ANYPTR is a pr

Re: [fpc-pascal] Pointer question

2023-08-10 Thread Elmar Haneke via fpc-pascal
1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" work the same? Subtracting pointers may be useful if they point to consecutive memory. The Result is the number of bytes between both addresses. Adding pointers is useless, you would get a pointer pointing to some

Re: [fpc-pascal] Pointer question

2023-08-09 Thread Tomas Hajny via fpc-pascal
On August 10, 2023 at 0:06:57 +0200, Hairy Pixels via fpc-pascal wrote: >> On Aug 9, 2023, at 2:54 PM, Tomas Hajny via fpc-pascal >> wrote: >> >>> >>> 1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + >>> x" work the same? >> >> Pointer subtraction is a reverse ope

Re: [fpc-pascal] Pointer question

2023-08-09 Thread Hairy Pixels via fpc-pascal
> On Aug 9, 2023, at 2:54 PM, Tomas Hajny via fpc-pascal > wrote: > >> >> 1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + >> x" work the same? > > Pointer subtraction is a reverse operation to adding a number to a pointer; > the result of the subtraction is the

Re: [fpc-pascal] Pointer question

2023-08-09 Thread Tomas Hajny via fpc-pascal
On August 9, 2023 at 22:14:17 +0200, Hairy Pixels via fpc-pascal wrote: >Playing around I had a more questions about pointer operations I've never used >myself. > >1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" >work the same? Pointer subtraction is a reverse op

Re: [fpc-pascal] Pointer question

2023-08-09 Thread Hairy Pixels via fpc-pascal
Playing around I had a more questions about pointer operations I've never used myself. 1) what does "i := x - x;" do and what is it's purpose and why doesn't "x + x" work the same? 2) I've used pointer equality of course but what does "x > p" do and what is its purpose? === var

Re: [fpc-pascal] Pointer question

2023-08-09 Thread Hairy Pixels via fpc-pascal
> On Aug 8, 2023, at 11:53 PM, Sven Barth via fpc-pascal > wrote: > > By default @ returns a *untyped* pointer that can be assigned to any pointer > type. Thus is compatible with Delphi and can be controlled with the > $TypedAddress directive (there's a slight exception to this when you ass

Re: [fpc-pascal] Pointer question

2023-08-08 Thread Sven Barth via fpc-pascal
Hairy Pixels via fpc-pascal schrieb am Mi., 9. Aug. 2023, 04:59: > I just noticed this by accident and I don't understand. Why does " x := > @r; " compile? I would expect it to fail like the next line where I cast to > the explicit type. > > type > TMyRec = record end; > PMyRec = ^TMyRec; > v

[fpc-pascal] Pointer question

2023-08-08 Thread Hairy Pixels via fpc-pascal
I just noticed this by accident and I don't understand. Why does " x := @r; " compile? I would expect it to fail like the next line where I cast to the explicit type. type TMyRec = record end; PMyRec = ^TMyRec; var x: PByte; r: TMyRec; begin x := @r;// works x := PMyR

Re: [fpc-pascal] pointer to char vs pchar

2023-03-27 Thread Sven Barth via fpc-pascal
Am 24.03.2023 um 15:04 schrieb Benito van der Zander via fpc-pascal: why is a pointer to a char not a pchar (for type helpers)? Because that's how helpers work in Delphi as well: The address operator has as a result an expression that allows the use of a helper for the raw Pointer type (no ma

Re: [fpc-pascal] pointer to char vs pchar

2023-03-24 Thread Michael Van Canneyt via fpc-pascal
On Fri, 24 Mar 2023, Peter B via fpc-pascal wrote: On 24/03/2023 14:29, Martin Frb via fpc-pascal wrote: On 24/03/2023 15:04, Benito van der Zander via fpc-pascal wrote: why is a pointer to a char not a pchar (for type helpers)? My guess: For the same reason that "p2" fails in the below.

Re: [fpc-pascal] pointer to char vs pchar

2023-03-24 Thread Peter B via fpc-pascal
On 24/03/2023 14:29, Martin Frb via fpc-pascal wrote: On 24/03/2023 15:04, Benito van der Zander via fpc-pascal wrote: why is a pointer to a char not a pchar (for type helpers)? My guess: For the same reason that "p2" fails in the below. Distinct type. May be assignment compatible, but a type

Re: [fpc-pascal] pointer to char vs pchar

2023-03-24 Thread Martin Frb via fpc-pascal
On 24/03/2023 15:04, Benito van der Zander via fpc-pascal wrote: why is a pointer to a char not a pchar (for type helpers)? My guess: For the same reason that "p2" fails in the below. Distinct type. May be assignment compatible, but a type of it's own. Imagine you had a different helper, with

[fpc-pascal] pointer to char vs pchar

2023-03-24 Thread Benito van der Zander via fpc-pascal
Hallo, why is a pointer to a char not a pchar (for type helpers)? program Project1; {$Mode objfpc}{$H+} {$ModeSwitch typehelpers} type TPcharHelper = type helper for pchar   function toString(length: integer): string; end; function TPcharHelper.toString(length: integer): string; begin   SetStr

Re: [fpc-pascal] Pointer hashing

2017-01-31 Thread Mark Morgan Lloyd
On 31/01/17 15:30, Ryan Joseph wrote: Thanks for answering guys. Yes José is right, hashing the pointer wasn’t even a good solution so I used another hash. I had the pointers stored in another data type and I wanted to quickly test for the their entry in the table but I found another way. On

Re: [fpc-pascal] Pointer hashing

2017-01-31 Thread Ryan Joseph
Thanks for answering guys. Yes José is right, hashing the pointer wasn’t even a good solution so I used another hash. I had the pointers stored in another data type and I wanted to quickly test for the their entry in the table but I found another way. > On Jan 30, 2017, at 4:28 PM, José Mejuto

Re: [fpc-pascal] Pointer hashing

2017-01-30 Thread José Mejuto
El 30/01/2017 a las 3:37, Ryan Joseph escribió: I’m trying to hash a pointer value and found some example of hash function but not sure about translations and the process in general. Hello, After addressing the ^ conversion showed by other people I have a question. Why you need to hash a po

Re: [fpc-pascal] Pointer hashing

2017-01-29 Thread Karoly Balogh (Charlie/SGR)
Hi, On Mon, 30 Jan 2017, Ryan Joseph wrote: > I?m trying to hash a pointer value and found some example of hash > function but not sure about translations and the process in general. > > 1) Should I cast ?pointer? as PtrUInt to get an integer from a pointer? > I?m looking for the memory address I

Re: [fpc-pascal] Pointer hashing

2017-01-29 Thread Marco van de Voort
In our previous episode, Ryan Joseph said: > > unsigned int hash(unsigned int x) { > x = ((x >> 16) ^ x) * 0x45d9f3b; > x = ((x >> 16) ^ x) * 0x45d9f3b; > x = (x >> 16) ^ x; > return x; > } > > function Hash (x: PtrUInt): PtrUInt; > begin > x := (Power((x shr 16), x)) * $45d9f3b

Re: [fpc-pascal] Pointer hashing

2017-01-29 Thread Lars
On Sun, January 29, 2017 7:37 pm, Ryan Joseph wrote: > I'm trying to hash a pointer value and found some example of hash > function but not sure about translations and the process in general. ... > x := (Power((x shr 16), x)) * $45d9f3b; x := Power((x shr 16), x); result := The math unit, is som

[fpc-pascal] Pointer hashing

2017-01-29 Thread Ryan Joseph
I’m trying to hash a pointer value and found some example of hash function but not sure about translations and the process in general. 1) Should I cast “pointer” as PtrUInt to get an integer from a pointer? I’m looking for the memory address I guess and casting seems to return a unique value. B

Re: [fpc-pascal] Pointer to a const char

2013-11-05 Thread Jonas Maebe
On 05 Nov 2013, at 09:07, Antonio Fortuny wrote: > I don't know a way to make the data pointed to, as being constant. There is indeed no way to specify that in Pascal. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.fre

Re: [fpc-pascal] Pointer to a const char

2013-11-05 Thread Antonio Fortuny
Le 04/11/2013 14:18, Alexander a écrit : How can I describe a "pointer to a constant char" in FreePascal? For example this C function: int some_func(const char *arg, ...); ... coulb be translated to some_proc(const arg: PChar, ...

Re: [fpc-pascal] Pointer to a const char

2013-11-05 Thread Michael Schnell
On 11/04/2013 02:18 PM, Alexander wrote: How can I describe a "pointer to a constant char" in FreePascal? For example this C function: int some_func(const char *arg, ...); My guess in FreePascal is this(with ctypes unit): function some_func(const arg: pcchar): cint; cdecl; external; A const

[fpc-pascal] Pointer to a const char

2013-11-04 Thread Alexander
How can I describe a "pointer to a constant char" in FreePascal? For example this C function: int some_func(const char *arg, ...); My guess in FreePascal is this(with ctypes unit): function some_func(const arg: pcchar): cint; cdecl; external; A constant argument to a function. I'm not sure, i

Re: [fpc-pascal] pointer address safety

2013-01-31 Thread ik
On Thu, Jan 31, 2013 at 10:25 PM, Sven Barth wrote: > On 31.01.2013 19:55, ik wrote: >> >> Hello, >> >> What is the safest (no memory corruption etc...) way to use format >> string, and by using '%P' pass a class memory address ? >> >> Does casting to Pointer good, or is it unsafe ? > > > As Forma

Re: [fpc-pascal] pointer address safety

2013-01-31 Thread Sven Barth
On 31.01.2013 19:55, ik wrote: Hello, What is the safest (no memory corruption etc...) way to use format string, and by using '%P' pass a class memory address ? Does casting to Pointer good, or is it unsafe ? As Format does not support objects being provided to it you MUST even cast to Point

[fpc-pascal] pointer address safety

2013-01-31 Thread ik
Hello, What is the safest (no memory corruption etc...) way to use format string, and by using '%P' pass a class memory address ? Does casting to Pointer good, or is it unsafe ? Thanks, Ido ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org ht

Re: [fpc-pascal] Pointer to temporary string

2012-03-11 Thread cobines
OK. Thanks, Jonas. I'll save a link to this message this time. -- cobines ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Pointer to temporary string

2012-03-11 Thread Jonas Maebe
On 11 Mar 2012, at 15:46, cobines wrote: > Is storing and using pointers to temporary strings safe? No. > Like in the > following program. I think I remember reading on the mailing list that > it is not, but I cannot find it. How can I prove one way or the other? The only thing you can prove i

[fpc-pascal] Pointer to temporary string

2012-03-11 Thread cobines
Hello. Is storing and using pointers to temporary strings safe? Like in the following program. I think I remember reading on the mailing list that it is not, but I cannot find it. How can I prove one way or the other? I could not get the program to crash, even if I used 20 variables, it didn't sho

Re: [fpc-pascal] pointer magic

2010-04-27 Thread Thierry Coq
... In addition, when starting to use Pascal, don't use pointers, and don't invent linked lists, it's been done so many times. Go look up the source code in contnrs.pp to understand lists and containers already available in FPC. Most programming can be done without untyped pointers. Best regar

Re: [fpc-pascal] pointer magic

2010-04-27 Thread cobines
2010/4/27 spir ☣ : > -1- untyped pointer allocation > In case of an untyped pointer, I read the compiler considers the target'size > is 1 byte. There certainly is an operation to allocate memory for the target > according to an existing piece of data. Something like >    data := something >    ne

[fpc-pascal] pointer magic

2010-04-27 Thread spir ☣
Hello, Two basic questions about pointer targets (I call target what is pointed to). -1- untyped pointer allocation In case of an untyped pointer, I read the compiler considers the target'size is 1 byte. There certainly is an operation to allocate memory for the target according to an existing

Re: [fpc-pascal] pointer to anything

2010-04-23 Thread Frank Peelo
On 23/04/2010 14:08, spir ☣ wrote: On Fri, 23 Apr 2010 08:17:21 -0400 Doug Chamberlin wrote: On 4/23/2010 3:33 AM, spir ☣ wrote: Say I want to implement a kind of linked list which node data may be anything. Thus I cannot store data on place (in nodes), indeed; so it should be referenced.

Re: [fpc-pascal] pointer to anything

2010-04-23 Thread tcoq
1° Using the root class TObject might be a good alternative? Storing any object within the structure is easy. Getting the object back will need a type overwrite. 2° Concerning standard structures, you might want to look at TList, TObjectList, TInterfacedList, TComponentList, TStringList which prov

Re: [fpc-pascal] pointer to anything

2010-04-23 Thread spir ☣
On Fri, 23 Apr 2010 08:17:21 -0400 Doug Chamberlin wrote: > On 4/23/2010 3:33 AM, spir ☣ wrote: > > Say I want to implement a kind of linked list which node data may be > > anything. Thus I cannot store data on place (in nodes), indeed; so it > > should be referenced. But pointers themselves ar

Re: [fpc-pascal] pointer to anything

2010-04-23 Thread Doug Chamberlin
On 4/23/2010 3:33 AM, spir ☣ wrote: Say I want to implement a kind of linked list which node data may be anything. Thus I cannot store data on place (in nodes), indeed; so it should be referenced. But pointers themselves are supposed to be typed. So, how can I do that? The key to solving

Re: [fpc-pascal] pointer to anything

2010-04-23 Thread ik
Try the following: type list = ^node; node = record data : Variant; next : list; end; Variant can store a lot pf data types, however please note that it's very slow type. You also must remember that Pascal is Strong typed, unlike C or duck type languages. The Pointer type st

[fpc-pascal] pointer to anything

2010-04-23 Thread spir ☣
Hello, Say I want to implement a kind of linked list which node data may be anything. Thus I cannot store data on place (in nodes), indeed; so it should be referenced. But pointers themselves are supposed to be typed. So, how can I do that? type list = ^node; node = record data : ?

Re: [fpc-pascal] Pointer to an array of PChar strings

2010-01-20 Thread Graeme Geldenhuys
2010/1/19 Marco van de Voort : > > where cfree is the free() corresponding to the malloc with which it was > allocated in the lib. (usually libc's) Thanks for the repy. In the end I found the library I was using was old. The newer library has a function that does the free'ing of that list for me.

Re: [fpc-pascal] Pointer to an array of PChar strings

2010-01-19 Thread Marco van de Voort
In our previous episode, Graeme Geldenhuys said: > > I'm working with a C library that returns an array of strings. So that is > type PPChar. I C library does the array allocation, but doesn't do the > freeing of the array. > > How am I supposed to free an array of PChar strings? I think I need

[fpc-pascal] Pointer to an array of PChar strings

2010-01-19 Thread Graeme Geldenhuys
Hi, I'm working with a C library that returns an array of strings. So that is type PPChar. I C library does the array allocation, but doesn't do the freeing of the array. How am I supposed to free an array of PChar strings? I think I need to improve my iteration too, because I'm moving the point

Re: [fpc-pascal] pointer arithmetic help required

2009-10-16 Thread Jürgen Hestermann
Now I know why vendors of newer languages (Dephi, Java etc) are trying to hide pointers from programmers. They are very tricky to work with - and give errors without warning! Especially when compiler and programmer are both trying to outsmart each other. :D Yes. But I never needed pointer arit

Re: [fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Vinzent Höfler
Graeme Geldenhuys : > Now I know why vendors of newer languages (Dephi, Java etc) are trying > to hide pointers from programmers. They are very tricky to work with - > and give errors without warning! Especially when compiler and programmer are both trying to outsmart each other. :D Vinzent. -

Re: [fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Graeme Geldenhuys
Martin wrote: > Graeme Geldenhuys wrote: >> By the way, I am reading in the Table of Contents data for an OS/2 INF file. >> >> >> // now increment pEntry to point to next data structure // below, .Length is in bytes inc( pEntry, pEntry^.Length); >>> inc(P

Re: [fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Martin
Graeme Geldenhuys wrote: By the way, I am reading in the Table of Contents data for an OS/2 INF file. // now increment pEntry to point to next data structure // below, .Length is in bytes inc( pEntry, pEntry^.Length); inc(PEntry, 1) since it increments by the size of the t

Re: [fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Graeme Geldenhuys
By the way, I am reading in the Table of Contents data for an OS/2 INF file. Martin wrote: >> > if pentry is > TEntry = record .. end; > pentry = ^ TEntry Yes, pEntry is a pointer to a structured type. pEntry: pTTOCEntryStart; The actual structure is as follows... -

Re: [fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Martin
Graeme Geldenhuys wrote: _pContentsData = a generic Pointer type that points to a block of data (containing multiples of various structures). XXX bytes of information. pEntry = this is a pointer to a specific starting structure type and will increment in blocks of data to point to the various st

[fpc-pascal] pointer arithmetic help required

2009-10-15 Thread Graeme Geldenhuys
Hi, Sorry, I suck at this pointers think. Currently I am reading one record in correctly and from there is all corrupted data. :-( Seeing that the first block of data (pEntry^ below) is correct, it seems my problem is incrementing to the next block of data. Here are the various variables I am wor

Re: [fpc-pascal] Pointer address into string

2008-05-05 Thread Damien Gerard
Le May 5, 2008 à 5:10 PM, ik a écrit : Look at the Format function, you can tell it to display the address of a pointer in a string. Thanks ! -- Damien Gerard [EMAIL PROTECTED] "Intelligence is 10 million rules." -- Douglas Lenat ___ fp

Re: [fpc-pascal] Pointer address into string

2008-05-05 Thread ik
Look at the Format function, you can tell it to display the address of a pointer in a string. Ido On Sun, May 4, 2008 at 7:21 PM, Damien Gerard <[EMAIL PROTECTED]> wrote: > > Hi ! > > I would like to display in a lazarus application the address of a pointer. > For this, I use : > > var s: str

[fpc-pascal] Pointer address into string

2008-05-05 Thread Damien Gerard
Hi ! I would like to display in a lazarus application the address of a pointer. For this, I use : var s: string; p:pointer; [...] s := IntToStr(PtrInt(p)) However, I've got a warning (hint) from the compiler : Conversion between ordinals and pointers is not portable What is the way to

[fpc-pascal] Pointer address into string

2008-05-05 Thread Damien Gerard
Hi ! I would like to display in a lazarus application the address of a pointer. For this, I use : var s: string; p:pointer; [...] s := IntToStr(PtrInt(p)) However, I've got a warning (hint) from the compiler : Conversion between ordinals and pointers is not portable What is the way to

Re: [fpc-pascal] Pointer

2005-11-16 Thread Felipe Monteiro de Carvalho
On 11/15/05, Luis Del Aguila <[EMAIL PROTECTED]> wrote: > > Somebody can help me. > I do not understand, that I am making bad. > The program is: What were you trying to do? and what was the result you expected? What does that program do? By the way your program is leaking memory. You call Reallo

Re: [fpc-pascal] Pointer

2005-11-16 Thread Jonas Maebe
On 15 nov 2005, at 17:11, Luis Del Aguila wrote: Somebody can help me. I do not understand, that I am making bad. The program is: Program ProbandoMemoria; {$R+} Var PLPunteros: ^Pointer; NuevoTamanio : integer; elementos : longint; x,b : ^integer; Begin elementos := 3; NuevoTamanio

[fpc-pascal] Pointer

2005-11-16 Thread Luis Del Aguila
Somebody can help me.I do not understand, that I am making bad. The program is: Program ProbandoMemoria;{$R+}Var    PLPunteros: ^Pointer;  NuevoTamanio : integer;  elementos : longint;  x,b : ^integer;Begin      elementos := 3;  NuevoTamanio:=Sizeof(Pointer)*elementos;  ReallocMem(PlPunter

Re: [fpc-pascal]Pointer Help

2003-02-10 Thread Jonas Maebe
On zondag, feb 9, 2003, at 15:06 Europe/Brussels, Anton Tichawa wrote: That's exactly what I meant: I'm not sure if fpc is able to keep track of the destruction of the strings in case of AnsiString. It is, as long as the type of the variable is clear when getmem/freemem is called (getmem also

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
On Sun, Feb 09, 2003 at 03:42:29PM +0100, Anton Tichawa wrote: > Hi, > > > But getMem and reAllocMem allocate a number of bytes on the heap, > > wouldn't you have to free that number of bytes using freeMem(pointer, n) > > ? > > No, Free Pascal keeps track of the allocated size for a pointer creat

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread Anton Tichawa
Hi, > But getMem and reAllocMem allocate a number of bytes on the heap, > wouldn't you have to free that number of bytes using freeMem(pointer, n) > ? No, Free Pascal keeps track of the allocated size for a pointer created with GetMem/ReallocMem. They need this information for heap management, s

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
On Sun, Feb 09, 2003 at 03:12:07PM +0100, Anton Tichawa wrote: > On Sunday 09 February 2003 12:54, you wrote: > > > freeMem(tmpStrings, sizeOf(String) * (N)); > > No, only: > > freeMem(tmpStrings); But getMem and reAllocMem allocate a number of bytes on the heap, wouldn't you have to free that

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread Anton Tichawa
On Sunday 09 February 2003 12:54, you wrote: > freeMem(tmpStrings, sizeOf(String) * (N)); No, only: freeMem(tmpStrings); Read the Manual - Free Pascal Programmer's Manual, Section 4.5, "Writing Your Own Memory Manager" - because that's what you're actually doing. HTH Anton Tichawa. --

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread Anton Tichawa
Hello, James! That's exactly what I meant: I'm not sure if fpc is able to keep track of the destruction of the strings in case of AnsiString. You might check it by displaying the total free memory before and after the deallocation of tmpStrings. But one of the developers might answer this quest

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
On Sun, Feb 09, 2003 at 02:22:55PM +0100, Anton Tichawa wrote: > Hello, James! > > I found an error at GetMem / ReAllocMem: Your code: > > getMem(tmpStrings, 100); > {reAllocMem(tmpStrings, (I + 1));} > > reserves 100 or (I + 1) BYTES, but you need space for 100 or (I + 1) > STRINGS, i. e.

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
On Sun, Feb 09, 2003 at 02:22:55PM +0100, Anton Tichawa wrote: > Hello, James! > > I found an error at GetMem / ReAllocMem: Your code: > > getMem(tmpStrings, 100); > {reAllocMem(tmpStrings, (I + 1));} > > reserves 100 or (I + 1) BYTES, but you need space for 100 or (I + 1) > STRINGS, i. e.

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread Anton Tichawa
Hello, James! I found an error at GetMem / ReAllocMem: Your code: getMem(tmpStrings, 100); {reAllocMem(tmpStrings, (I + 1));} reserves 100 or (I + 1) BYTES, but you need space for 100 or (I + 1) STRINGS, i. e. the code should be: getMem(tmpStrings, SizeOf(String) * 100); {reAllocMem(tm

Re: [fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
On Sun, Feb 09, 2003 at 08:30:57PM +1000, James Mills wrote: > Hi all, > > Sorry if this is trivial, but I'm sick of it :) > I'm using fpc to convert my (originally delphi) code to read and write > ini style files, however writing will not work as I want, the data in > the pointer keeps getting fi

[fpc-pascal]Pointer Help

2003-02-09 Thread James Mills
Hi all, Sorry if this is trivial, but I'm sick of it :) I'm using fpc to convert my (originally delphi) code to read and write ini style files, however writing will not work as I want, the data in the pointer keeps getting filled with junk. I'm using getMem, and reAllocMem functions to create dyn