9.COMPILE DIRECTIVES
A Programming Language Manual





9.1 Global defines

In GS9 language, global defines are very similar to the global variables. The difference is that they can have the value (and a type) associated right when they are declared. But those values can only be integers, floats and strings. Here's an example:



They are representing global constants, used through the program and, as a convention, they are written in upper case, so the reader knows they are not usual variables.

If in a program we often need to use the application's title, it is recomended to keep it in such a define. This way, if you decide at some point to change the name, you will not have to do it in every place you used it.

Even if the defines are actually global variables, it is recomended to be treated as constants and not change their values. There is more about those defines, but for the level of this book, this is enough.


9.2 Include files

As programs become bigger and bigger, they need to be more structured. You learned so far to structure programs in more functions and now, you will learn how to structure them in more than one file.

Consider you have a set of similar functions that represent a well defined part of your program. Like some function that work with strings, or do some math calculations. It is recomended to write them in a separate file and include that file in the main program file. This way it will be easy for you to replace it with another version, or to take it and use it in other programs as well.

Create a new file called module.txt in the console folder and write inside the folowing lines of code:



In the main file, our program.txt write:



The #include directive, followed by the name of the file to be included, in quotation marks, acts like the whole text from the specified file would have been written right in that place.

Since GS9 functions don't need to be declared before used, you can include the module files anywhere in your program (usually in the main file). But if you have global variables or defines declared inside those files, you must take care of the include order.