- This wiki is out of date, use the continuation of this wiki instead
Include
From FenixWiki
Revision as of 14:48, 19 March 2008 (edit) 212.123.12.180 (Talk) (New page: Category:filetypes == Definition == Include files to the current file. These files (*.INC) contain code that gets appended to the current file. == See also == * INC {{Filetyp...) ← Previous diff |
Current revision (16:02, 19 March 2008) (edit) (undo) Sandman (Talk | contribs) m (→Example) |
||
(3 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
- | [[Category: | + | [[Category:General]] |
+ | [[Category:Language]] | ||
+ | |||
== Definition == | == Definition == | ||
- | Include files to the current file. These files (*.[[INC]]) contain code that gets appended to the current file. | ||
- | + | '''Include''' "<filename>"; | |
- | * [[INC]] | + | |
+ | When the compiler reaches an [[Include]] statement, it continues compilation at the included file (usually *.[[FH]] or *.[[INC]]) and when it's done resumes compiling from the [[Include]] statement. In other words, these files contain code that gets inserted at the place of inclusion. | ||
+ | |||
+ | This is very handy for breaking up your code into pieces. The handling of video in one include file, audio in another, game logic in another, etc. This makes code more maintainable and understandable; moreover it makes code reusable. The video handling include file you made for one game can be used for another game (if it was coded in a generic fashion) without spitting through the whole sourcecode of the first game. | ||
+ | |||
+ | Also headers can be used to import [[DLL]]s and possibly give a little more functionality to that DLL. For example [[Network.DLL]] uses a .[[FH]] header file to assure the DLL is only imported once during compilation and provides a little more functionality. | ||
+ | |||
+ | == Example == | ||
+ | '''main.prg''' | ||
+ | <pre> | ||
+ | // The code in "bar.inc" will be processed first: | ||
+ | include "bar.inc"; | ||
+ | |||
+ | Process Main() | ||
+ | Private | ||
+ | int barcode; | ||
+ | Begin | ||
+ | write_int(0,100,100,0,&barcode); | ||
+ | barcode = bar(); | ||
+ | repeat | ||
+ | frame; | ||
+ | until(key(_ESC)) | ||
+ | End | ||
+ | </pre> | ||
- | + | '''bar.inc''' | |
+ | <pre> | ||
+ | Function int bar() | ||
+ | Begin | ||
+ | return 5; | ||
+ | End | ||
+ | </pre> | ||
+ | Used in example: [[Include]], [[write_int]](), [[key]]() |
Current revision
[edit] Definition
Include "<filename>";
When the compiler reaches an Include statement, it continues compilation at the included file (usually *.FH or *.INC) and when it's done resumes compiling from the Include statement. In other words, these files contain code that gets inserted at the place of inclusion.
This is very handy for breaking up your code into pieces. The handling of video in one include file, audio in another, game logic in another, etc. This makes code more maintainable and understandable; moreover it makes code reusable. The video handling include file you made for one game can be used for another game (if it was coded in a generic fashion) without spitting through the whole sourcecode of the first game.
Also headers can be used to import DLLs and possibly give a little more functionality to that DLL. For example Network.DLL uses a .FH header file to assure the DLL is only imported once during compilation and provides a little more functionality.
[edit] Example
main.prg
// The code in "bar.inc" will be processed first: include "bar.inc"; Process Main() Private int barcode; Begin write_int(0,100,100,0,&barcode); barcode = bar(); repeat frame; until(key(_ESC)) End
bar.inc
Function int bar() Begin return 5; End