Preprocessor Directives

Preprocessor directives are special statements that begin with a pound # sign, and are the only ones that don't need the semi-colon ; at the end.

Preprocessor directives must be in a linear order, and BEFORE the code to keep certain errors from coming up.

There are two important directives:

  • #include "filename"

    Includes a file to be compiled in addition to SYSTEM.VC. This is recommended to have a neat categorizing of your codes. The filename is quotes and must also have the extension at the end of the filename with it.

    Example:

    #include "draw.vc"
    
  • #define A B

    #define is basically a seek-replace statement. Every spot the identifier A is used will be replaced with their value B, which is everything after A until the next line (so B can be an expression, a short piece of code, a symbol, etc). You can use a define like you would a string or int but since their value is substituted wherever they're found, they have a constant value during runtime. It can be used for things such as file paths, debugging code, or keeping track of numeric constants. They are also used in Verge's built-in library as scan codes and color filters, among other things.

    Example:

    #define MAX_PARTY_MEMBERS 5
    int party_index[MAX_PARTY_MEMBERS]; 
    
Talkback

Post a new comment?

Talkback #1 written by Gayo on 2004-07-15.

A few further notes on #define are warranted.

Order is important for #defines; if I #define MAX_PARTY_MEMBERS to 5, the #define statement must come before any instance of MAX_PARTY_MEMBERS in the code. For this reason, you should put all your #defines before the code that uses them. #included files are read by the compiler in the order in which they are #included, so if you #include a file containing a define, that define is valid for anything below the #include statement (including other #included files), as well as for anything below it in the included file.

The preprocessor will not redefine tokens within other #define statements. That is to say, if I code:


#define A_VALUE 1
#define ANOTHER_VALUE A_VALUE

...the compiler will return an error when trying to evaluate the second statement. A_VALUE is #defined to be 1, but the preprocessor will not change the A_VALUE in the second line since it is within the body of a #define statement.

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.