What exactly is a translation unit in C

后端 未结 4 1150
旧巷少年郎
旧巷少年郎 2021-01-03 23:59

The commonly used definition of a translation unit is what comes after preprocessing (header files inclusions, macros, etc along with the source file). This definit

4条回答
  •  一生所求
    2021-01-04 00:50

    In the second line you quoted:

    The text of the program is kept in units called source files, (or preprocessing files) in this International Standard

    If there are two source files then there are two preprocessing files, and therefore two preprocessing translation units, and therefore two translation units. One corresponding to each source file.

    The standard doesn't define source file. I guess the compiler could say "I'm making up my own version of 'source file' by declaring that file1.c and file2.c are not source files after all!" and concatenate them, but this would be at odds with programmer expectations. I think you would have a hard time arguing that file1.c is not a source file.

提交回复
热议问题