C++: Compiler and Linker functionality

后端 未结 8 496
野趣味
野趣味 2020-12-10 08:39

I want to understand exactly which part of a program compiler looks at and which the linker looks at. So I wrote the following code:

#include          


        
8条回答
  •  被撕碎了的回忆
    2020-12-10 08:59

    The missing semi-colon is a syntax error and therefore the code should not compile. This might happen even in a template implementation. Essentially, there is a parsing stage and whilst it is obvious to a human how to "fix and recover" a compiler doesn't have to do that. It can't just "imagine the semi-colon is there because that's what you meant" and continue.

    A linker looks for function definitions to call where they are required. It isn't required here so there is no complaint. There is no error in this file as such, as even if it were required, it might not be implemented in this particular compilation unit. The linker is responsible for collecting together different compilation units, i.e. "linking" them.

提交回复
热议问题