[fpc-pascal] New feature: IfThen() intrinsic

Sven Barth pascaldragon at googlemail.com
Tue Feb 2 11:40:12 CET 2016


Am 02.02.2016 11:27 schrieb "Michael Van Canneyt" <michael at freepascal.org>:
>
>
>
> On Tue, 2 Feb 2016, Serguei TARASSOV wrote:
>
>> On 02/02/2016 10:54, fpc-pascal-request at lists.freepascal.org wrote:
>>
>>> On Tue, 2 Feb 2016, Michael Van Canneyt wrote
>>>>
>>>>
>>>> On Tue, 2 Feb 2016, Serguei TARASSOV wrote: > No, the second is always
better because safer.
>>>> >
>>>> >x := iif (Obj = nil, 0, Obj.Value);
>>>> >This will raise access violation as a normal function or you depend on
>>>> >compiler implementation for this special case. And you should
remember an
>>>> >additional special case of function.
>>>> >
>>>> >x := iif Obj = nil then 0 else Obj.Value;
>>>> >Doesn't raise AV because it's a statement, not function.
>>>
>>> It is not a statement, it is an expression.
>>
>> ???
>> iif is a new statement "inline if".
>> It contains other statements "then" "else"
>> It returns a value like an assignment statement ":=" in Pascal or
"return" in C-like languages.
>> It may be used without assignment:
>>
>> {$IFDEF DEBUG}
>> x :=
>> {$ENDIF}
>> iif Obj = nil then 0 else Obj.DoSomethingAndReturnValue;
>
>
> I doubt this is what Sven implemented/will implement. The assignment will
always be needed.
> But Sven will have to comment on that.

Indeed.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160202/e971e653/attachment.html>


More information about the fpc-pascal mailing list