?: - Selection of one of two values

Top  Previous  Next

Syntax

<result> := (<condition> ? <value1> : <value2> )

Parameters

<condition>

 

An expression checked with the Empty() function to select either <value1> or <value2> as return value.

 

<value1>

 

The value to return if the value of <condition> is not empty.

 

<value2>

 

The value to return if the value of <condition> is empty.

Resulting Code

A call to the Xbase++ function IIf in which <condition> is checked with the Empty function and passed as first parameter. In case the value of <condition> is empty, <value2> is returned, otherwise <value1> is returned.

Description

The ?: macro is resolved by a call to the IIf function. It is provided to facilitate porting of C code. The C function is very much like the Xbase++ IIf function, but it is based on a numeric condition value. If <condition> is not equal to zero, <value1> is returned, otherwise <value2>. This behavior is reproduced by applying the Empty function and inverting the result by swapping the values to return. The ?: macro will work for any data type of <condition>. For logicals it behaves like Xbase++ IIf and for numerics it behaves like the C ?: operation.

Classification

Core

Category

C compatibility macros

Quick Info

Library: cckptcor.lib / cckptcor.dll

Header: cmacros.ch

Example

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "cmacros.ch"

 

FUNCTION Main

 

* This will display #0

? (2-1 ? "#0": "==0")

 

* This will display FALSE

? (.F. ? "TRUE", "FALSE" )

 

RETURN NIL