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 semantics are not right IMHO, but I'd have to see the original C stuff to be able to say with certainty.

It's not C, it's Javascript :-(

    this.P1 = (this.PB1L ? this.PB : this.PA);
    this.P2 = (this.PB1L ? this.PA : this.PB);

where PB1L is 0 or 1, PA and PB are objects representing emulated CPUs (one or more defined), P1 indicates the first (master) CPU and P2 indicates the second (slave). PB1L was- on the original system- a switch on the engineer's panel indicating which of the processors was to run as the master (i.e. it handled the MCP, all interrupts and so on) and which as the slave.

I thought it would be good practice to abstract the conditional operator to a function- noting the unavoidable problem that both parameters will be evaluated, which is not really an issue when they're simple object references- but it's beginning to look as though it would be far simpler to have a simple if statement inline.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to