Using c99 (with Examples)
Compile source file(s) and create an executable
c99 file.c
Motivation: This use case is for compiling a single C source file without any specific options. It is useful when you have a simple C program that does not require any additional configuration.
Explanation: The c99
command is used to compile C programs according to the ISO C standard. When used without any options, it expects a C source file as input and will compile it into an executable.
Example Output: If file.c
is a valid C source file, the command will generate an executable file named a.out
, which can be executed to run the program.
Compile source file(s) and create an executable with a custom name
c99 -o executable_name file.c
Motivation: This use case is for compiling a C source file and specifying a custom name for the executable. It is useful when you want to have a more meaningful or specific name for the resulting executable.
Explanation: The -o
option is used to specify the name of the executable that will be created. By providing executable_name
after the -o
option, the c99
command will generate an executable with the specified name.
Example Output: If file.c
is a valid C source file and executable_name
is set to my_program
, the command will generate an executable file named my_program
, which can be executed to run the program.
Compile source file(s) and create object file(s)
c99 -c file.c
Motivation: This use case is for compiling a C source file and creating an object file without linking it. It is useful when you want to separately compile multiple source files and then link them later.
Explanation: The -c
option is used to compile the source file(s) into object file(s) without performing the linking stage. This is useful when you have multiple source files that need to be compiled separately and then linked together later.
Example Output: If file.c
is a valid C source file, the command will generate an object file named file.o
, which can be used as input for the linking stage.
Compile source file(s), link with object file(s), and create an executable
c99 file.c file.o
Motivation: This use case is for compiling a C source file and linking it with one or more object files to create an executable. It is useful when you have multiple source files that depend on each other and need to be linked together.
Explanation: The c99
command can take multiple source files as input and it will compile and link them together to create an executable. In this case, file.c
and file.o
are provided as input, where file.o
is the object file generated from a separate compilation.
Example Output: If file.c
and file.o
are both valid, the command will generate an executable file named a.out
, which can be executed to run the program.
Conclusion
In this article, we explored various use cases of the c99
command for compiling C programs according to the ISO C standard. We learned how to compile a single source file, create an executable with a custom name, create object files, and link them together to create an executable. These examples provide a starting point for building and executing C programs using the c99
command-line tool.