Header Files, Makefiles, Processes, and Signals Flashcards
(40 cards)
What should you do to prevent errors when using #define?
Use #define wisely.
What is important to remember about structuring code?
Structure code into multiple files (.c and .h).
What is the benefit of using Makefiles?
Automate compilation.
Fill in the blank: A library is a collection of _______.
Precompiled functions.
What is the role of *.h (Header files) in C programming?
Declarations & interfaces.
What do *.c (Source files) contain?
Code definitions, logic.
What elements are included in headers?
- # include <stdio.h></stdio.h>
- # define macros (e.g. M_PI)
- struct definitions
- typedefs
- Function prototypes
What elements are excluded from headers?
- Function bodies (definitions)
- Executable code
What does the file stack.h contain?
Structure & function prototypes.
What is the purpose of include guards in C headers?
Prevent duplicate definitions in headers.
What is the syntax for include guards?
ifndef __STACK_H
#define __STACK_H
// … header content …
#endif
What is an alternative to include guards?
pragma once
What is the command to compile a C source file into an object file?
gcc -c stack.c
What is the command to link object files into an executable?
gcc myProgram.o stack.o -o myProgram
What are the two types of libraries in C?
- Static (.a)
- Dynamic (.so)
What is the linker flag to use the math library in C?
-lm
What is the purpose of Makefiles?
Automate compilation.
What command is used to run the Makefile?
make myProgram
What happens when a dependency like stack.h is updated?
Recompile if any dependency is updated.
Fill in the blank: Header files contain ______, not definitions.
Declarations.
What does the command gcc -c file.c do?
Creates object files.
What is a key point about libraries in C?
Use -l<name> for others.</name>
What is one advantage of using Makefiles?
Keep project organized.
What is a Process?
A running instance of a program with a unique PID and one parent process, except for PID 0.