Research Group of Prof. Dr. C. Burstedde
Institute for Numerical Simulation
maximize

Coding guidelines

We aim to combine the efforts of multiple people in programming useful functions. Each group should be able to use the contributions of others without duplicating work or interfering with the work of others.

We split the code into a header file to expose the prototype and a source file with the code of the function. We proceed at the example of Aufgabe 1.

These would be the contents of the file a1.h:
/* The following preprocessor macros allow for multiple inclusion */
#ifndef V5E3_A1
#define V5E3_A1

/* This construct allows to use both C and C++ compilers in a project */
#ifdef __cplusplus
extern "C" {
#endif

void aValues (int n, double alpha, double* a);

#ifdef __cplusplus
}
#endif
#endif
Then the file a1.c would contain the following:
#include <math.h>    /* if needed */
#include "a1.h"

/* This function must match a1.h exactly */
void aValues (int n, double alpha, double* a)
{
  /* write the code of the function here */
}
Share a1.c and a1.h with the other groups. Compile into an object file a1.o by say gcc -Wall -c a1.c and repeat this for all exercise files you want to use. If you have one or more test programs with one main function each, they would look like this example_abc.c:
#include <stdio.h>
#include "a1.h"
#include "a2.h"
/* etc. */

int main (int argc, char ** argv) {

  /* Use the functions declared in the .h files */
  aValues (n, alpha, a);
}
This can be compiled with gcc -Wall -o abc example_abc.c a1.o a2.o -lm. You may want to read about Makefiles to automate the compilation process.