FBWiki : KeyPgPpdefine

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

#DEFINE


Preprocessor directive to define a macro

Syntax:
#define identifier text
#define identifier([parameters]) macro_text

Description:
Preprocessor keyword that defines an identifier with a custom meaning:

Identifiers can be checked to see whether they have been defined with #ifdef and #ifndef, which can be used to hide parts of code to the compiler (conditional compiling).

For defining identifiers with constant values associated with them Const may be used as a more powerful method.

Examples:
'' Definition and check
#define DEBUGGING
#ifdef DEBUGGING
  ' ... statements
#endif

'' Simple definition/text replacement
#define FALSE 0
#define TRUE (Not FALSE)

'' Function like definition
#define MyRGB(R,G,B) (((R)Shl 16)  Or ((G)Shl 8) Or (B))
Print Hex( MyRGB(&hff, &h00, &hff) )

'' Line continuation and statements in a definition
#define printval(bar) _
    Print #bar; " ="; bar

'' #defines are visible only in the scope where they are defined
Scope
    #define LOCALDEF 1
End Scope

#ifndef LOCALDEF
#    Print LOCALDEF Is Not defined
#endif

'' namespaces have no effect on the visibility of a define
Namespace foo
#    define NSDEF
End Namespace

#ifdef NSDEF
#    Print NSDEF Is defined
#endif


Differences from QB:

See also:

Back to Preprocessor

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode