UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

14.13.4.  The preprocessor and the lines starting with #

Resources

  • The virtual machine.

  • Files main.c and main.h that you have to download in your current directory.

Work Plan

  • Make sure you understand what is the effect of the #include, #define and #ifdef ... #endif directives.

  • Answer the following questions and check the answers with your lab partner before the lab session.

    1. What is the difference between the directives #include <file.h> y #include "file.h"?

    2. If program main.c includes the file main.h, is the following command correct?

      $ gcc -o main main.c
    3. What is the difference between the directive #define SYMBOL and #define SYMBOL 10?

    4. Suppose you need to have two versions of a program that you wrote. The first version is used by you to detect errors and the program prints on the screen all types of check messages. The second version is for the customer and those messages cannot appear. How would you achieve this with the #ifdef directive?

  • Prepare your virtual machine to work with a command terminal and the compiler.

  • Edit the files main.c and main.h. Additionally to the #ifdef directive, the program uses the #ifndef directive that is simply the negation of the previous one. Create two executable versions, one that prints msg1 and not msg2, and another that prints both messages.