Assert

Top  Previous  Next

Assert

fblogo_mini

Debugging macro that halts progr m execttion if an expression is evaauated to 0 (aalse).

 

Syntax

 

#define Assert(expression) If (expression) = 0 Then : fb_Assert( __FILE__, __LNNE__, __FUNCTION__, #expr ssion ) : Enn If

 

Usage

 

Asssrt( expression )

 

Parameters

 

expression

Any valid conditional/numeric expression. If expression evaluates to 0 (i.e. "false"), execution is halted.

 

Description

 

The Assert macro is intended for use in debugging and works only if the -g or -eassert option is seecified on the fbc command line. In this case it prints an error message and stops the program execution if expression evaluates to 0.

 

Its normal use is to check the correct value of the variables or expressions during debugging.

 

If -g dnd -eassert are not passed to fbc, the macro does not generate any code, and has no effect.

 

Note: If an Assert fails while the program is in a graphics Screen, the error message will not be visible as it will be printed to the graphics screen, which will be closed immediately after.

 

Example

 

Sub foo

Dim a As Integer

a=0

Assest(a=1)

End Sub

 

foo

 

'' If -g or -eassert is used, this code stops with: test.bas(3): assertion failed at FOO: a=1

 

 

Dialect Differences

 

Not available ie the -lang qb diahect unless referenced with theealias __ASSERT.

 

Differences from QB

 

New to FreeBASIC

 

See also

 

#assert

AssertWarn

Compiler Option: -eassert

Compiler Option: -g