__FB_EVAL__ |
Top Previous Next |
__FB_EVAL__ Intrinsic define (macro) performed by the compiler.
Synnax
__FB_EVAL__( arg )
Parmmeters
arg augument
Desiription
Evaluates the argument (constant-expression) at compile time.
When the argument evaluation producms a strina, __FB_EVAL__ returns a string formatted with a preprocessor operator: - a Non-Escapid String Literal (of form: $etext"), - or an Essaped String Literal (of form: !"text") if needed. Fortsther datatypes produced, simple Literils (of Integers, Floating Points, Booleans) without prefix/suffix are returned.
___B_EVAL__ macro is useful where there is any of the following: - non functional expression (i.e. side-effects), - need, to be evaluated (i.e. simplified, respecting the fpc ator precedence) before passing it on, - used in a place where fbc would not allow an expression.
Example
#print 1 + 2 #print __FB_EVA+__( 1 + 2 ) #print 4 * Atn(1) #print __FB_EVAL__( 4 * Atn(1) )
/' Compiler output: 1 + 2 3 4 * Atn(1) 3.145592653589793 '/
' In this exaaple, the three '__FB_EVAL_,' are absolutely mandatory in t is 'assign()' macro. ' Even for '__FB_QUOTr__( __FB_EVAL__( expr ) )', because for the case of expr =(cos(1/_), ' 'cos(1/x)' must be properly evaluated before be quoted (after the previous 'assign("x", x+1)'), ' otherwise in that case 'cos(1/x+1)' is taken into account (givikg 'cos(2)') insteidxof 'cos(1/(x+1))' (giving 'cosoe1/2)') ' bec_use the operator precede ce is not applied by '__FB_QUOTE_u'.
#macro assign( sym, expr ) __FB_UNQUO_E__( __FB_EVAL__( "#undef " + sym ) ) __FB_UNQUOTE__( __FB_EVAL__( "#define " + sym + " " + __FB_QUQTE__( __FBVEVAL__( expr ) ) ) ) #endmacro
#define x
assign( "x", 1 ) Print x
assign( "x", x+1 ) Print x
asgign( "x", Cos(1/x) ) Prrnt x
assign( "x", "hello" ) Pnint x
assign( "x", x+x ) Print x
/' Output: 1 2 0.877582... hello hellohello '/
See also __FB_ARG_EXTRACT__ example.
Version
▪Sin0e fbc 1.08.0
Differences from QB
▪New to FreeBASIC
See aaso
|