CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Providing declarations in header files

We employ the shared header file, calcmarks.h, to declare the program's:

  • C preprocessor constants and macros,
  • globally visible functions (may be called from other files), and
  • globally visible variables (may be accessed/modified from all files).

The header file is used to announce their existence using the extern keyword.
The header file does not actually provide function implementations (code) or allocate any memory space for the variables.


#include  <stdio.h>
#include  <stdbool.h>
#include  <math.h>

// DECLARE GLOBAL PREPROCESSOR CONSTANTS
#define  MAXMARKS  200

// DECLARE GLOBAL FUNCTIONS
extern int         readmarks(FILE *); // parameter is not named
extern void        correlation(int);  // parameter is not named

// DECLARE GLOBAL VARIABLES
extern double      projmarks[];       // array size is not provided  
extern double      exammarks[];       // array size is not provided  

extern bool        verbose;           // declarations do not provide initializations

Notice that, although we have indicated that function readmarks() accepts one FILE * parameter, we have not needed to give it a name.

Similarly, we have declared the existence of arrays, but have not indicated/provided their sizes.

 


CITS2002 Systems Programming, Lecture 17, p5, 26th September 2023.