Sign in Join

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

Mailing lists / fpc-pascal / 2011-01

Re: AnsiString (Luis Fernando Del Aguila Mej?a)

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Luis Fernando Del Aguila Mejía

Thanks for the tip, David.
My intention is to learn or acquire knowledge.
True the function Length is easier to use, but it's always good to know the internals of the compiler.
You never know when something may go wrong.

Thanks

Earlier message 352 lines
----- Original Message ----- From: To: Sent: Wednesday, January 26, 2011 6:00 AM Subject: fpc-pascal Digest, Vol 79, Issue 46 > Send fpc-pascal mailing list submissions to > > > To subscribe or unsubscribe via the World Wide Web, visit > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > or, via email, send a message with subject or body 'help' to > > > You can reach the person managing the list at > > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of fpc-pascal digest..." > > > Today's Topics: > > 1. AnsiString (Luis Fernando Del Aguila Mej?a) > 2. Re: AnsiString (David Emerson) > 3. Re: AnsiString (J?rgen Hestermann) > 4. linking error while cross compiling win64 -> Linux64 > (Julien Devillers) > 5. compiling 2.4.2 under 7-64 (Julien Devillers) > 6. Re: compiling 2.4.2 under 7-64 (Marco van de Voort) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 25 Jan 2011 10:13:13 -0500 > From: Luis Fernando Del Aguila Mej?a > Subject: [fpc-pascal] AnsiString > To: > Message-ID: > Content-Type: text/plain; format=flowed; charset="utf-8"; > reply-type=original > > The documentation > (http://www.freepascal.org/docs-html/prog/progsu146.html#x189-1990008.2.7) > says: > -8 Longint current string with size. > -4 Longint with reference count. > But, when I want access to that structure, I have to do it backwards. > -8 Longint with reference count. > -4 Longint current string with size. > > {$codepage UTF8} > Var > cad1:AnsiString; > aux1:AnsiString; > p:pointer; > Begin > > SetLength(cad1,8); > > p:=pointer(cad1); > Writeln('memory address : ',longint(p)); > p:=p-4; > Write('memory address : ',longint(p),'='); > //Must show reference count, but shows size > Writeln(longint(p^)); > > aux1:=cad1; > > p:=pointer(cad1); > p:=p-8; > Write('memory address : ',longint(p),'='); > //Must show Size, but shows reference count > Writeln(longint(p^)); > > End. > > Do these positions are different, depending on microprocessor being used ? > > Thanks > > > > > ------------------------------ > > Message: 2 > Date: Tue, 25 Jan 2011 11:23:36 -0800 > From: David Emerson > Subject: Re: [fpc-pascal] AnsiString > To: FPC-Pascal users discussions > Message-ID: > Content-Type: text/plain; charset="utf-8" > > Luis Fernando Del Aguila Mejía wrote: >> The documentation >> (http://www.freepascal.org/docs-html/prog/progsu146.html#x189-1990008.2.7) >> says: >> -8 Longint current string with size. >> -4 Longint with reference count. >> But, when I want access to that structure, I have to do it backwards. >> -8 Longint with reference count. >> -4 Longint current string with size. > >> Do these positions are different, depending on microprocessor being used >> ? > > I'm fairly certain that is an error in the documentation, and that it > SHOULD > always be as you discovered it to actually be. > > > As an aside, a tip for doing pointer arithmetic... > > var > s : ansistring; > p : ptruint; > > p := pointer(s); > dec(p); // equivalent to p:=p-4 because p is a typed pointer. > > Using typed pointers in this way will likely make it easier to adapt your > code > to a 64-bit conversion in the future. > > Also note that, in this case, dec(p,2) would do p:=p-8, as (hopefully) > expected > > I use these types of constructs frequently, and it makes it much easier to > change types, if that is ever necessary, or adapt constructs to new types. > > Cheers, > David > > > > ------------------------------ > > Message: 3 > Date: Wed, 26 Jan 2011 07:50:01 +0100 > From: J?rgen Hestermann > Subject: Re: [fpc-pascal] AnsiString > To: FPC-Pascal users discussions > Message-ID: > Content-Type: text/plain; charset=UTF-8; format=flowed > > Luis Fernando Del Aguila Mejía schrieb: > > p:=pointer(cad1); > > p:=p-8; > > Write('memory address : ',longint(p),'='); //Must show Size, but > shows reference count > > Writeln(longint(p^)); > > I fail to see why you need to mess with the internals of ansistrings at > all. > What is the reason to access size and reference count this way? > At least for the size there is Length(cad1) which would be much clearer. > > Although pointer arithmetic is possible in Pascal it looks like C. > And you loose any help from the compiler to check types. > > > > ------------------------------ > > Message: 4 > Date: Tue, 25 Jan 2011 17:19:42 +0100 > From: "Julien Devillers" > Subject: [fpc-pascal] linking error while cross compiling win64 -> > Linux64 > To: > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > Hi > > = > > > I have a linking error with the following compile command : > > = > > > =E8 d:\pp\bin\x86_64-win64\fpc > lib\snip\snip.dpr -Tlinux -n -va -Mdelphi -F= > uD:\pp\bin\x86_64-win64/../../units/$FPCTARGET/ = > > > = > > > In the above line, I removed lots of includes. The error is (founded in > th= > e below log) > > =E8 "D:\dev\devtools\MinGW\mingw\bin\ld.exe: unrecognised emulation mode: > e= > lf_x86_64" = > > > = > > > [1.367] Searching file D:\dev\devtools\MinGW\mingw\bin\ld.exe... found > > [1.371] Using util D:\dev\devtools\MinGW\mingw\bin\ld.exe > > D:\dev\devtools\MinGW\mingw\bin\ld.exe: unrecognised emulation mode: > elf_x8= > 6_64 > > Supported emulations: i386pe > > [1.523] Error while linking > > [1.523] There were 1 errors compiling module, stopping > > [1.523] Compilation aborted > > Error: d:\pp\bin\x86_64-win64\ppcx64.exe returned an error exitcode > (normal= > if you did not specify a source file to be compiled) > > = > > > Maybe I don't use the right ld.exe file ? > > I'm running fpc 2.4.0 > > = > > > regards > > Julien > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://lists.freepascal.org/lists/fpc-pascal/attachments/20110125/5063= > 8212/attachment.html > > ------------------------------ > > Message: 5 > Date: Tue, 25 Jan 2011 18:11:28 +0100 > From: "Julien Devillers" > Subject: [fpc-pascal] compiling 2.4.2 under 7-64 > To: > Message-ID: > > Content-Type: text/plain; charset="iso-8859-1" > > Hi > > = > > > i'm trying to compile fpc 2.4.2 under windows 7 64 bits. > > It raises the following error : > > = > > > = > > > make[5]: entrant dans le r=E9pertoire =AB C:/FPC/2.4.2/fpc-2.4.2/rtl/win32 > = > =BB > > c:/gnuwin32/bin/gmkdir.exe -p C:/FPC/2.4.2/fpc-2.4.2/rtl/units/i386-win32 > > d:/pp_/bin/i386-win32/ppc386.exe -Ur -Xs -O2 -n -Fi../inc -Fi../i386 -Fi../= > win -FE. -FUC:/FPC/2.4.2/fpc-2.4.2/rtl/units/i386-win32 -di386 -dRELEASE - > > s -Sg system.pp -Fi../win > > system.pp(1011) Error: Can't create archive file: > C:\FPC\2.4.2\fpc-2.4.2\rt= > l\units\i386-win32\libimpsystem.a > > = > > > Instead of making the C:/FPC/2.4.2/fpc-2.4.2/rtl/units/i386-win32, gmkdir > c= > reates a directory named : > C:\FPC\2.4.2\fpc-2.4.2\rtl\win32\FPC\2.4.2\fpc= > -2.4.2\rtl\units\i386-win32 > > = > > > Should I consider that this is a bug of gmkdir ? I get this file with > getGn= > uWin32. > > = > > > regards > > Julien > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://lists.freepascal.org/lists/fpc-pascal/attachments/20110125/21b2= > b8c3/attachment-0001.htm > > ------------------------------ > > Message: 6 > Date: Wed, 26 Jan 2011 10:37:56 +0100 (CET) > From: (Marco van de Voort) > Subject: Re: [fpc-pascal] compiling 2.4.2 under 7-64 > To: FPC-Pascal users discussions > Message-ID: > Content-Type: text/plain; charset="US-ASCII" > > In our previous episode, Julien Devillers said: > >> Should I consider that this is a bug of gmkdir ? I get this file with >> getGnuWin32. > > Use the binutils that come with FPC, not the ones from mingw. mingw's > coreutils package has afaik moved in a different direction since it moved > from mingw to msys. > > That also goes for the linker problem: > > ftp://ftp.freepascal.org/pub/fpc/contrib/cross/mingw/win64/ > > is where the win64 binutils are kept. > > > ------------------------------ > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > End of fpc-pascal Digest, Vol 79, Issue 46 > ****************************************** >
Jonas Maebe
to Luis Fernando Del Aguila Mejía
Luis Fernando Del Aguila Mejía wrote
Thanks for the tip, David. My intention is to learn or acquire knowledge. True the function Length is easier to use, but it's always good to know the internals of the compiler. You never know when something may go wrong.

The problem is that many people who learn the internals of a compiler also start to depend on these internals. And that is a very good recipe to write code that will go wrong at some point.

Jonas