Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Misc > Re: freepascal ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 19 Topic 718 of 811
Post > Topic >>

Re: freepascal strings

by "Richard Engebretson" <eng@[EMAIL PROTECTED] > Feb 19, 2007 at 09:37 AM

On Feb 19, 8:22 am, Wolf Behrenhoff
<NoSpamPleaseButThisIsVal...@[EMAIL PROTECTED]
> wrote:
> Richard Engebretson schrieb:
>
> > I have looked hard at AnsiStrings (not the source). They try to bridge
> > the turbo with delphi pascal. But I am avoiding the delphi mode. The
> > delphi mode hides pointers and has other secrets that confuse me.
>
> The AnsiString type is also a hidden pointer :-)
> I think it is a good idea to hide pointers if possible. Anyway, I agree
> that the hidden pointer in the "class" type might confuse someone wo was
> using "object" before.
>
> > My basic point is pascal has some very nice string types. Pascal is
> > NOT like C and that is good.
>
> Agree. I don't like C's null-terminated strings.
>
> > My only disagreement is AFAIK the string is not copied to the stack in
> > the first a) case, as one would expect. But is passed by reference.
> > However, this is very unclear to me.
>
> Hm... I did a simple test (see below). The program will produce a stack
> overflow. If you change the maximum length of the string, the number of
> recursions will change! This number would be constant if just a pointer
> was copied to the stack.
>
> I didn't look at fpc - but Turbo Pascal does the following when foo is
> called:
> - it pushes the number to the stack
> - it pushes the address of the string (so, you're right, it is passed by
> reference; also in case a). BUT the foo procedure itself then does a
> "sub sp, sizeof(str)" and copies the string. But that is just an
> internal detail, I don't know if FPC does it the same way.
>
> Wolf
>
> Test program:
>
> type
>  str=string[100]; (* change the number *)
>
> procedure foo(nr: integer; s:str);
> begin
>   writeln(nr);
>   foo(nr+1, s);
> end;
>
> var
>   s:str;
> begin
>   foo(0,s);
> end.


I am running your test on a linux virtual console using nr:longint.
Still running after over 125,000 recursions. Don't know ?? 175,000 ...
snorrr :-)
 




 19 Posts in Topic:
freepascal strings
"Richard Engebretson  2007-02-17 19:16:39 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-18 14:01:05 
Re: freepascal strings
"Richard Engebretson  2007-02-19 03:13:17 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 15:22:41 
Re: freepascal strings
CBFalconer <cbfalconer  2007-02-19 19:04:06 
Re: freepascal strings
"Richard Engebretson  2007-02-19 09:09:46 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 20:41:13 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 22:09:24 
Re: freepascal strings
Marco van de Voort <ma  2007-02-20 08:38:07 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-20 13:58:34 
Re: freepascal strings
Jonas Maebe <Jonas.Mae  2007-02-20 14:58:14 
Re: freepascal strings
"Richard Engebretson  2007-02-19 09:37:20 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 21:19:34 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 20:43:07 
Re: freepascal strings
Wolf Behrenhoff <NoSpa  2007-02-19 21:56:35 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 21:19:37 
Re: freepascal strings
Marco van de Voort <ma  2007-02-19 21:27:00 
Re: freepascal strings
CBFalconer <cbfalconer  2007-02-19 19:07:59 
Re: freepascal strings
"Richard Engebretson  2007-02-19 13:15:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 0:45:48 CDT 2008.