Pragmatic directives: Difference between revisions

Added PureBasic
(Added FreeBASIC)
(Added PureBasic)
Line 724:
Get-Help about_Requires
</syntaxhighlight>
 
=={{header|PureBasic}}==
PureBasic supports several pragmatic directives, also known as '''compiler directives'''.
 
<code>CompilerIf…CompilerElseIf…CompilerElse…CompilerEndIf</code>: allows certain parts of the code to be compiled depending on the evaluation of a constant expression.
<syntaxhighlight lang="vb">CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; some Linux specific code
CompilerElse
; some code for other operating systems
CompilerEndIf</syntaxhighlight>
 
<code>CompilerSelect…CompilerCase…CompilerDefault…CompilerEndSelect</code>: Allows you to select which code to compile based on a constant numeric value.
<syntaxhighlight lang="vb">CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_MacOS
; some Mac OS
CompilerCase #PB_OS_Linux
; some Linux specific code
CompilerEndSelect</syntaxhighlight>
 
<code>CompilerError</code> and <code>CompilerWarning</code>: generate an error or a warning, respectively.
<syntaxhighlight lang="vb">CompilerIf #PB_Compiler_OS = #PB_OS_Linux
CompilerError "Linux is not supported, sorry."
CompilerElse
CompilerWarning "OS supported, you can now comment me."
CompilerEndIf</syntaxhighlight>
 
<code>EnableExplicit</code> and <code>DisableExplicit1</code>: Enable or disable explicit mode. When enabled, all variables not explicitly declared with Define, Global, Protected, or Static will not be accepted and the compiler will generate an error.
<syntaxhighlight lang="vb">EnableExplicit
Defines
a = 20 ; Ok, as declared with 'Define'
b = 10 ; Will raise an error here</syntaxhighlight>
 
<code>EnableASM</code> and <code>DisableASM</code>: Enable or disable the inline assembler. When enabled, all assembler keywords are available directly in the source code.
<syntaxhighlight lang="vb">; x86 assembly example
Test = 10
EnableASM
MOV dword [v_Test],20
DisableASM
DebugTest ; Will be 20</syntaxhighlight>
 
It is important to note that the scope of these directives is global, that is, they affect all code after them until a directive is found that disables them or until the end of the code file.
 
=={{header|Python}}==
2,122

edits