- This wiki is out of date, use the continuation of this wiki instead
Precompiler define
From FenixWiki
Revision as of 15:41, 30 December 2007 (edit) Sandman (Talk | contribs) ← Previous diff |
Current revision (15:56, 30 December 2007) (edit) (undo) Sandman (Talk | contribs) m (→Error codes) |
||
(3 intermediate revisions not shown.) | |||
Line 9: | Line 9: | ||
== Example == | == Example == | ||
+ | === Basic statements === | ||
In the following example, we'll show it is possible to define words as "being" [[basic statements]]. | In the following example, we'll show it is possible to define words as "being" [[basic statements]]. | ||
<pre> | <pre> | ||
Line 25: | Line 26: | ||
Used in example: [[Program]], [[Process]], [[Begin]], [[End]] | Used in example: [[Program]], [[Process]], [[Begin]], [[End]] | ||
+ | === Error codes === | ||
Error codes are handy as well, like used in [[Network.DLL]] and [[LCD.DLL]]: | Error codes are handy as well, like used in [[Network.DLL]] and [[LCD.DLL]]: | ||
<pre> | <pre> | ||
#define NET_ERROR_INVALIDADDRESS -12 | #define NET_ERROR_INVALIDADDRESS -12 | ||
</pre> | </pre> | ||
- | This will enable the use of NET_ERROR_INVALIDADDRESS as it it were the value -12. This makes it much more clear for the programmer what the errors are. Consider this: | + | This will enable the use of ''NET_ERROR_INVALIDADDRESS'' as it it were the value ''-12''. This makes it much more clear for the programmer what the errors are. Consider this: |
<pre> | <pre> | ||
#define NET_STATUS_ESTABLISHED 2 | #define NET_STATUS_ESTABLISHED 2 | ||
Line 35: | Line 37: | ||
The value ''2'' on itself means very little, but ''NET_STATUS_ESTABLISHED'' immediately makes it clear what it means. | The value ''2'' on itself means very little, but ''NET_STATUS_ESTABLISHED'' immediately makes it clear what it means. | ||
+ | === Function === | ||
In the following we define a function ''kill(<int processID|processTypeID>,<string reason>)''. | In the following we define a function ''kill(<int processID|processTypeID>,<string reason>)''. | ||
<pre> | <pre> | ||
#define kill(a,b) if(exists(a)) signal(a,s_kill); say("Killed '" + a + "' for reason: " + b); end | #define kill(a,b) if(exists(a)) signal(a,s_kill); say("Killed '" + a + "' for reason: " + b); end | ||
Program example; | Program example; | ||
+ | Private | ||
+ | int i; | ||
Begin | Begin | ||
- | | + | i = proc(); |
- | kill( | + | kill(i,"It had to be killed!"); // The ';' is not needed per se, but is allowed. |
Repeat | Repeat | ||
frame; | frame; | ||
Line 53: | Line 58: | ||
End | End | ||
</pre> | </pre> | ||
+ | Used in example: [[Program]], [[Process]], [[Begin]], [[End]], [[If]], [[Repeat]], [[Until]], [[frame]], [[signal]](), [[say]](), [[key]]() | ||
{{Precompiler_statements}} | {{Precompiler_statements}} |
Current revision
Contents |
[edit] Definition
#define <what to define> [<what it will be>]
Defines what to define as what it will be. This means that after this line, all what to defines will be "replaced" by what it will be.
You can also create "functions" with this, even with parameters. The call to this "function", including parameters, will be replaced by the what it will be section, with the parameters replaced by the arguments.
[edit] Example
[edit] Basic statements
In the following example, we'll show it is possible to define words as "being" basic statements.
#define StartThisShow Program #define GimmeSomeShit Process StartThisShow example; Begin proc(); End GimmeSomeShit proc() Begin End
Used in example: Program, Process, Begin, End
[edit] Error codes
Error codes are handy as well, like used in Network.DLL and LCD.DLL:
#define NET_ERROR_INVALIDADDRESS -12
This will enable the use of NET_ERROR_INVALIDADDRESS as it it were the value -12. This makes it much more clear for the programmer what the errors are. Consider this:
#define NET_STATUS_ESTABLISHED 2
The value 2 on itself means very little, but NET_STATUS_ESTABLISHED immediately makes it clear what it means.
[edit] Function
In the following we define a function kill(<int processID|processTypeID>,<string reason>).
#define kill(a,b) if(exists(a)) signal(a,s_kill); say("Killed '" + a + "' for reason: " + b); end Program example; Private int i; Begin i = proc(); kill(i,"It had to be killed!"); // The ';' is not needed per se, but is allowed. Repeat frame; Until(key(_ESC)) End Process proc() Begin Loop frame; End End
Used in example: Program, Process, Begin, End, If, Repeat, Until, frame, signal(), say(), key()
Precompiler statements | |
#define • #ifdef • #ifndef • #endif • #else • #if |