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 11 of 19 Topic 718 of 811
Post > Topic >>

Re: freepascal strings

by Jonas Maebe <Jonas.Maebe@[EMAIL PROTECTED] > Feb 20, 2007 at 02:58 PM

In article <45daf07b$0$15941$9b4e6d93@[EMAIL PROTECTED]
>,
 Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@[EMAIL PROTECTED]
> wrote:

> Marco van de Voort schrieb:
> > I think the current system allows for easier optimization of non
mutated
> > by-value strings. But first, you will have to define "problem". I
don't see
> > the actual problem here?
> > 
> > Why would you want caller pu****ng?
> 
> Well, there is no problem. It was the first time I was looking at the
> internals in string parameters. I was just surprised to see how it
> actually works. My "problem" was that I didn't know WHY it is done this
> way. I was just guessing. Probably you're right, it could be for
> optimization and/or performance issues.

The reason is simply that this puts the string copying code once inside 
the called procedure/function body, rather than everywhere the function 
is called.

The copying of by-value strings is never optimized away to avoid code 
like this giving unexpected results:

***
procedure test(s1: string; var s2: string);
begin
  s2 := '';
  if (s1 = '') then
    writeln('problem');
end;

var
  s: string;
begin
  s := 'hello';
  test(s,s);
end.
***

In principle, it could nevertheless be done if all of the following 
conditions hold:
a) the procedure has no var/out string parameters
b) the procedure does not change any global string variables
c) the procedure does not write to any pointer location (or string 
pointer location if you turn on strict aliasing).

In general, it's easier and less error prone to simply require the 
programmer to use "const".


Jonas
 




 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 Fri Jul 25 18:52:47 CDT 2008.