Revision [12495]

This is an old revision of KeyPgPpdefine made by JeffMarshall on 2008-01-19 09:42:52.

 

#DEFINE


Preprocessor directive to define a macro

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

Description:
Preprocessor keyword that defines an identifier with a custom meaning:
  • Empty defines (without text) can be checked for existence with KeyPgPpifdef #ifdef and KeyPgPpifndef #ifndef to hide parts of code to the compiler (conditional compiling).
  • Non-empty defines (with text) are substituted by its text when the source is parsed, allowing a sort of "shorthand".
  • Defines with parameters are substituted by the macro_text, that will contain all the arguments passed replaced. Note: The open parentheses character ('(') must immediately follow the identifier, there should be no white-spaces between them.
  • Defines are visible only in the scope where they are defined. If defined at module level, the define is visible throughout the module. If the identifier is defined inside a compound statement having scope (KeyPgSub Sub, KeyPgFornext For..Next, KeyPgWhilewend While..Wend, KeyPgDoloop Do..Loop, KeyPgScope Scope..End Scope, etc), the identifier is visible only within that scope.
  • Namespaces do not have any effect on the visibility of a define.

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
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode