Skip to content

FB_IIF


Intrinsic define (macro) performed by the compiler.

Syntax

` FB_IIF( compare-expr, true-expr, false-expr )

`

Parameters

compare-expr

The comparison expression to test.

A non-zero value evaluates as true, while a value of zero evaluates as false.

true-expr

Source code to return if compare-expr is true.

false-expr

Source code to return if compare-expr is false.

Description

__FB_IIF__ returns source code text depending on the result of a comparison expression evaluated at preprocessing-time.

Its typical use is in the middle of an expression; it avoids splitting it to put a conditional in the middle.

This intrinsic define (macro) differs from the IIF conditional statement in that __FB_IIF__ is evaluated at compile-time only and returns source code text. IIF is evaluated at compile-time only if the compare-expr is a constant. Otherwise IIF expressions are evaluated at run-time.

Examples

start GeSHi

vb
' From the example of the '#ELSE' documentation page:
    '#DEFINE MODULE_VERSION 1
    'Dim a As String
    '#IF (MODULE_VERSION > 0)
    '    a = "Release"
    '#ELSE
    '    a = "Beta"
    '#ENDIF
    'Print "Program is "; a

' Simpler code using '__FB_IIF__':
    #DEFINE MODULE_VERSION 1
    Dim a As String
    a = __FB_IIF__( MODULE_VERSION > 0, "Release", "Beta" )
    Print "Program is "; a

end GeSHi

Version

  • Since fbc 1.10.0

Differences from QB

  • New to FreeBASIC

See also

  • #if
  • #else
  • #endif

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft