Header Files (.bi)

Provides an interface for a module.

A header file is a special kind of source file that typically only contains preprocessor statements, defines, declarations, prototypes, constants, enumerations, or similar types of statements, however, a header file can contain any valid source code if the purpose suits. What makes them different from other module (.bas) source files, is instead of being compiled directly, they are included by another source file (module or header) using the #include preprocessor directive. All compiled libraries typically have one or more header files that can be included in another source file and will introduce to the compiler all the names of the procedures usable in a particular library.

FreeBASIC Header Files
Some of the keywords, constants, and procedures documented in this manual are not normally available when compiling a source code unless a specific header file is included in the source first.

Case Sensitivity
Although the FreeBASIC language itself is not case-sensitive, the file system on which it is running might be. If a header file can not be found, check that FreeBASIC is searching for it the correct location and ensure that name of both the directory and filename of the header file specified in the #include statement is using the correct upper and lower case letters.

Path Separators
FreeBASIC will automatically switch backslash ( \ ) and forward slash ( / ) characters as needed for a given platform. This allows source code to be easily cross compatible.

Including a header only once
It is common that header files need to #include other header files to compile correctly. FreeBASIC offers three methods for guarding against including a header file more than once.

#ifndef guards in the header file
The use of #ifndef and #define is a common practice in nearly any language that supports preprocessing. The first time a file is included, a unique symbol is defined. The next time the same header file is included, the definition of the symbol is checked, and if it is already defined, the contents of the header file are skipped.
'' header.bi
#ifndef __HEADER_BI__
#define __HEADER_BI__

#print These statements will only be included once,
#print even though header.bi might be included more
#print than once in the same source file.


#include once
At the point in the source code where the header file is included, the optional "once" specifier of the #include directive can tell the compiler to only include the source file one time.
'' header.bi
#include once "fbgfx.bi"

'' module.bas
#include once "fbgfx.bi"
#include once "header.bi"

#pragma once
#pragma once can be used in a header file to indicate that the header file should only be included once.
'' header.bi
#pragma once
#print This header will only ever be included once per module

See also:
Back to Programmer's Guide
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki

sf.net phatcode