On 02 Jul 2014, at 12:26, Virgo Pärna wrote:

On Wed, 2 Jul 2014 11:23:33 +0200, Jonas Maebe <jonas.ma...@elis.ugent.be > wrote:

As has been mentioned earler in the thread, MyReturnStr itself is a
pchar.

Sorry, I had to recheck thred multiple times before I found it. Initially
he did not mention the type at all.

I know, that's why I initially also wrongly assumed that it was an ansistring and hence also proposed @MyReturnStr[1] in my first reply.

Anyway, if variable is of type PChar, then there is not reason to take an address of first element to pass it to PChar. Passing wariable itselt is
much clearer.

I disagree. People make mistakes all the time with dynamic data structures, forgetting that they are implicit pointers (or getting run time errors when they change the type of a variable from a static into a dynamic one). Passing the address of the first element is however always correct. The only downside is that the index of the first element may change, although for strings it won't (unless you switch to {$zerobasedstrings}) and for arrays you could solve that with @MyReturnStr[low(MyReturnStr)] (in case you often replace arrays with one using a different lower bound -- but in that case, other code may break too).


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to