[fpc-pascal] Checking assignment compatibility
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon Jan 6 10:47:29 CET 2014
On 06 Jan 2014, at 10:31, Michael Van Canneyt wrote:
> On Mon, 6 Jan 2014, Mark Morgan Lloyd wrote:
>
>> Michael Van Canneyt wrote:
>>> On Sun, 5 Jan 2014, Mark Morgan Lloyd wrote:
>>>> Simulating a C-style conditional, I can do this
>>>> function tf(const q: qword; const qt, qf: TObject): TObject;
>>>> inline;
>>>> begin
>>>> Assert(TypeOf(qt) = TypeOf(result));
>>> This is always true. Everything descends from TOBject.
>>> But assuming the result is not TObject, it would be
>>> Assert((qt=Nil) or (qt.Inheritsfrom(TheResultClass))
>>
>> So again skipping the nil check for simplicity, this compiles but
>> are the semantics right?
>>
>> Assert(qt.ClassType.InheritsFrom(result.ClassType));
>
> The classtype is not needed.
The first one, at least.
> The semantics are not right IMHO, but I'd have to see the original C
> stuff to be able to say with certainty.
Regardless of what the original C stuff was, the above is wrong
because "result" is uninitialised. Inside the function you cannot know
the type of whatever the result will be assigned to on the caller
side. Maybe instead of "result" it should be "qf".
Jonas
More information about the fpc-pascal
mailing list