What exactly is the source file for the C11 standard

I have doubts about the proposal in this paragraph of the C11 standard:

5.1.1.1 Program structure

The C program does not have to be translated at the same time. The text of a program is stored in units called source files (or preprocessing in this International Standard. The source file, along with all the headers and source files included in the #include preprocessing directive, is called the preprocessing block.

First, it says that the text of a program is stored in units called source files. After it says that the source file along with the headers and source files is considered a transmitting preprocessing unit.

So, the source file is another object related to the header file, or the source file includes how?

+3


source to share


3 answers


A source file is any text file (or other implementation-specific object as per Basile's answer) that contains the source code. This includes both files .c

and .h

. It can also include files with other suffixes, such as preprocessor or generated code files.

When you take some source file actually passed to the compiler (usually just files .c

), that file, along with (transitive closure) of everything it #include

forms a translation unit.



So: each translation unit is built from source files.

But: not every source file is the starting point of a translation unit.

+4


source


Pedantically, a source file (in the sense of the C99 or C11 standard) is not even necessarily a file (in the sense of an operating system). A conforming implementation can read a "source file" from a database, or some constant string inside some program.

IBM's own compiler in the 1990s ( VisualAge ???) was rumored to have gotten a compilation source from some database. Today tinycc also provides a library libtcc

with a function tcc_compile_string

to compile a string. TinyCC compiles slow machine code very quickly.



In practice, there are multiple source files (such as files .h

and .c

) that are processed in the same compilation or translation unit .

IIUC, the funny thing about the C standards is that they don't require a filesystem to be implemented. I believe the standard doesn't even require a computer; you can apply the standard unethically by using a bunch of human slaves, but it is immoral and ineffective.

+2


source


The term source file (or preprocessing file) reflects both the original file .c

and the header .h

. The C standard does not distinguish them as such.

This is explicitly mentioned in C. N. King's book C Programming: A Modern Approach (Section 15.2).

+1


source







All Articles