Tokens
White-Space Characters
Space, tab, linefeed, carriage-return, form-feed, vertical-tab and newline characters are called “white-space characters” because they serve the same purpose as spaces between words in a sentence on a page. In GXC, they serve to separate tokens and make GXC source code more readable. When reading source code, the GXC compiler ignores white-space characters except when they are used to separate tokens and as part of character constants or strings. Note that the compiler also treats comments as white space.
Comments
A comment is a sequence of characters that begins with a forward slash – asterisk (/*) and ends with an asterisk – forward slash (*/). For example:
/* This is a comment. This is a continuation of the comment. */
GXC also supports single-line comments preceded by two forward slashes as in the following example:
// This is a valid comment in GXC // You can place it on the same line as code, or on a separate line // Everything from the double slash to the next newline character is treated as a comment.
Keywords
Keywords are are tokens that have special meaning to the GXC compiler. They consist of the following:
break | case | continue | default | DESCRIPTION |
do | else | for | if | int |
NAME | real | RESOURCE | sizeof | string |
switch | typedef | VERSION | void | while |
GX-specific keywords consist of the NAME, VERSION, DESCRIPTION and RESOURCE keywords listed above. These identify graphical resources and special sections in Source files to the compiler. The other keywords are implemented exactly as in the C language.
Keyword names cannot be used for any purpose other than the defined by GXC. However, identifier names can be replaced by the pre-processor if they have been redefined using a #define statement (Hint: Don't do that!)
Identifiers
“Identifiers”, or “symbols” are the names that you supply for variables and functions in your programs. You cannot use a keyword as an identifier name. You create an identifier by specifying it in the declaration of a variable or function. You cannot use an identifier unless it has been declared.
We strongly recommend that you begin all identifier names with a lowercase character that describes the data type, or in the case of functions, the function return value. This makes your code much easier to read and maintain. You will find the following recommended prefix characters and their data types used in the Geosoft GX code:
i | an integer |
r | a real (floating-point) |
s | a string |
h | a class handle (This convention is often used in Geosoft source code, but not always. Identifiers that begin with an upper-case character can usually be assumed to be class handles.) |