GEOS Programming: 2.1 Goc and C: Goc File Types

Up: GEOS SDK TechDocs | Up | Prev: 2 Goc and C | Next: 2.2 Conditional Code in Goc
@include, @optimize

When programming in Goc, you will use several different types of code files. Files ending in .goh are the Goc equivalent of C .h files--they contain routine headers, constants, and other included data and structures necessary for the program. Files ending in .goc are the Goc equivalent of C .c files--they contain code and data for the program. You should keep any Goc-specific code or header information strictly in the Goc files, and standard C code should be kept in C files. C code can also be put in .goc and .goh files, but for consistency, you should try to keep it separate.

Not all of your program's header files need be .goh files--if the header file contains only C constructions (structures, routine definitions, and so on), then you may leave it as a standard C .h file, included by means of the #include directive.

The rule of thumb is that if a header file contains any Goc code or includes a .goh file, then it must be a .goh file. Note also that .goh files are allowed to contain simple standard C code; if you are not sure, then, you can make all your header files .goh .

Standard C programs use the #include directive to include header ( .h ) files. When using Goc, you can use this directive in standard .c and .h files; when including .goh files in .goc files, though, you have to use the @include directive, which is Goc-specific. It has the same syntax as #include .

An example of using @include comes from the Hello World application, which includes the stdapp.goh file. (All GEOS applications will need to include this file to compile properly; it must be @include d before any standard C headers are #include d.) The line from Hello World is

@include <stdapp.goh>

The syntax of this directive, as stated above, is the same as for the C directive #include . One exception is that the @include directive will include a file just once, even if it is included by an included file--there is no need to conditionally include a file (checking first to make sure it hasn't already been included).

If you will be including a Goc file in many different applications, or if it is very long and elaborate, it is a good idea to put the keyword @optimize at the top of the file. This instructs the Goc preprocessor to generate a special stripped-down version of the file with a .poh suffix. The compiler will then automatically keep the .poh file up to date, and use it in compilations instead of the .goh file. The .poh file contains all the data of the .goh file, but is somewhat faster to compile into an application; thus, by using the @optimize keyword, you incur a longer compilation whenever you make a change to the .goh file, but a shorter compilation time when the .goh file is unchanged since the last compilation. You may choose to leave the @optimize directive out while the header is being developed, then put it in when the header is fairly stable.


Up: GEOS SDK TechDocs | Up | Prev: 2 Goc and C | Next: 2.2 Conditional Code in Goc