Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-18 Thread Virgo Pärna
On Wed, 16 Dec 2015 23:21:27 +0100, Jonas Maebe  
wrote:
>
> As far as I know, Delphi only has errors and warnings. It does not have 
> separate categories such as notes and hints, unlike FPC.
>

Delphi does have hints. But no notes.

-- 
Virgo Pärna 
virgo.pa...@mail.ee

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

Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Bart
On 12/16/15, Jonas Maebe  wrote:

> We could, but that would be an extremely ugly hack.

Yes I know it's very ugly.
But D7 does not give me a warning on FillChar().

But agreed, we should avoid being ugly ;-)

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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Jonas Maebe

On 16/12/15 18:14, Bart wrote:

On 12/16/15, Jonas Maebe  wrote:


We could, but that would be an extremely ugly hack.


Yes I know it's very ugly.
But D7 does not give me a warning on FillChar().


We don't give a warning either. The category of hints was created 
exactly for those messages that have a high chance of being a false 
positive.



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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Jonas Maebe

On 16/12/15 23:16, Bart wrote:

On 12/16/15, Jonas Maebe  wrote:


But D7 does not give me a warning on FillChar().


We don't give a warning either. The category of hints was created
exactly for those messages that have a high chance of being a false
positive.


That should have been:
My D7 does not give me a warning or hint on FillChar().


As far as I know, Delphi only has errors and warnings. It does not have 
separate categories such as notes and hints, unlike FPC.



Jonas

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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Bart
On 12/16/15, Jonas Maebe  wrote:

>> But D7 does not give me a warning on FillChar().
>
> We don't give a warning either. The category of hints was created
> exactly for those messages that have a high chance of being a false
> positive.

That should have been:
My D7 does not give me a warning or hint on FillChar().

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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Bart
On 12/16/15, Jonas Maebe  wrote:

> As far as I know, Delphi only has errors and warnings. It does not have
> separate categories such as notes and hints, unlike FPC.

I hardly ever use Delphi anymore for many years now, so you might be right.
Let's stop this discussion, it's getting a bit OT and a bit silly ;-)

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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Jonas Maebe


Santiago A. wrote on Wed, 16 Dec 2015:


In functions blockread and blockwrite, the result parameter is "var".
And in blockread buffer is also "var".

Couldn't they be marked as "out" instead of "var"?.


The result parameters can be changed. The BlockRead buffer parameter  
cannot be changed for the same reason that the parameters of fillchar  
and move cannot be changed: it changes the behaviour in case a managed  
type, or e.g. a record or array containing managed types, it passed.  
With "var", nothing special happens, while with "out", they are first  
finalised. If they are not yet initialised at that point (e.g. because  
they are the result of a plain getmem), this would introduce crashes.


Even though you cannot just blockread/blockwrite managed types anyway  
(since they are pointers), this can currently work if you ensure that  
all read/written managed types are nil. It may seem unlikely, but at  
least changing the "var" parameters of move/fillchar to "out" even  
caused crashes in the compiler because the RTL relies on the current  
behaviour (and using move/fillchar with managed types is not very  
common/recommended either in the general case).



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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Frederic Da Vitoria
2015-12-16 11:55 GMT+01:00 Jonas Maebe :

>
> Santiago A. wrote on Wed, 16 Dec 2015:
>
> In functions blockread and blockwrite, the result parameter is "var".
>> And in blockread buffer is also "var".
>>
>> Couldn't they be marked as "out" instead of "var"?.
>>
>
> The result parameters can be changed. The BlockRead buffer parameter
> cannot be changed for the same reason that the parameters of fillchar and
> move cannot be changed: it changes the behaviour in case a managed type, or
> e.g. a record or array containing managed types, it passed. With "var",
> nothing special happens, while with "out", they are first finalised. If
> they are not yet initialised at that point (e.g. because they are the
> result of a plain getmem), this would introduce crashes.
>
> Even though you cannot just blockread/blockwrite managed types anyway
> (since they are pointers), this can currently work if you ensure that all
> read/written managed types are nil. It may seem unlikely, but at least
> changing the "var" parameters of move/fillchar to "out" even caused crashes
> in the compiler because the RTL relies on the current behaviour (and using
> move/fillchar with managed types is not very common/recommended either in
> the general case).
>

Thank you Jonas for this answer. This has been frustrating me, at least now
I have an idea why.

Now what I should do is add {%H-} on each line containing blockread,
blockwrite, fillchar and so on... This isn't so difficult, after all. The
only drawback is that it could potentially hide another perfectly valid
warning.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Santiago A.
El 16/12/2015 a las 11:55, Jonas Maebe escribió:
> while with "out", they are first finalised
Sorry, what does this mean?

-- 
Saludos

Santi
s...@ciberpiula.net

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

[fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Santiago A.
In functions blockread and blockwrite, the result parameter is "var".
And in blockread buffer is also "var".

Couldn't they be marked as "out" instead of "var"?.
It's not an aesthetic or academic change,  I would save a lot of  "not
initialized" warnings that flood the message window.

Of course I could use compiler directives to remove that warning, or
initialize the actual parameter. But why should we waste time setting a
dummy value that, in fact, it's always going to be ignored and overwritten?
Couldn't the parameter be changed to "out" to avoid these warnings that
are false positives?

-- 
Saludos
Santiago A.

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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Jonas Maebe


Bart wrote on Wed, 16 Dec 2015:


Can't we hardcode the compiler to not give a hint on FillChar and related?
Especially since these are used to initialize (null) variables.


We could, but that would be an extremely ugly hack. You can always  
write and use your own wrapper if you know that you won't be bitten by  
the side-effects of "out"


procedure MyFillChar(out data; size: sizeuint; value: byte);
  begin
fillchar(data,size,value);
  end;


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


Re: [fpc-pascal] Blockread blockwrite var vs out parameters

2015-12-16 Thread Frederic Da Vitoria
2015-12-16 16:19 GMT+01:00 Jonas Maebe :

>
> Santiago A. wrote on Wed, 16 Dec 2015:
>
> El 16/12/2015 a las 11:55, Jonas Maebe escribió:
>>
>>> while with "out", they are first finalised
>>>
>> Sorry, what does this mean?
>>
>
> http://www.freepascal.org/docs-html/rtl/system/finalize.html
>

Not important, but there is a typo there: "necessaru"

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal