2016-07-28 13:30 GMT+02:00 Michael Van Canneyt <mich...@freepascal.org>: > > Assume a is null before the call to test1: > > test1(a); >
That won't compile. > > 1. What happens if this procedure is empty, i.e. no write is performed ? > (or it is performed conditionally) > On return, is a null or not ? > You are not able to call test1 in presented form (you will get error: Incompatible types). > 2. Assume your variable is null before the call to Test1. > What is the value on entry into Test1 ? i.e. what happens if > > begin > if X=0 then > x:=1 > else > X:=23; > end > That won't compile too. The correct code: === code begin === if x.HasValue and (x^ = 0) then x := 1 else x := 23; === code end === or === code begin === if x.GetValueOrDefault = 0 then x := 1 else x := 23; === code end === 3. How do you detect an actual write ? > > 4. What happens if Test1 is an external C procedure ? It depend on context. If we have: x := 1; // is detected in class operator Implicit(A: T): TNullable<T>; when you use x^ := 1; // you are operating directly on Instance field in that case if x.HasValue is false you will get EAccessViolation -- Best regards, Maciej Izak
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel