by green7ea on 11/14/18, 9:27 PM with 126 comments
by wahern on 11/15/18, 5:38 AM
In C and C++ parlance "definition" should be "declaration" and "implementation" should be "definition".[1] The terminology is important if you don't want to get confused when learning more about C and C++. This is compounded by the fact that some languages describe these roles in the author's original terms. (Perhaps the author's terminology reflects his own confusion in this regard?)
[1] This is indisputable given the surrounding context, but I didn't want to paste 3-4 whole paragraphs.
by aidenn0 on 11/15/18, 12:03 AM
Prelinker:
1. Compile each file, noting which templates are needed in a section in the object file
2. Have a special program called the "prelinker" run before the linker that reads each .o file, and then somehow instantiates each template (which usually, but not always requires reparsing the C++ file)
Weak Symbols:
1. When compiling instantiate every needed template, but mark it somehow in the object file as being weak, so that the linker only pulls in one instantiation for each definition.
The prelinker used to be more popular, as if you e.g. instantiate the same template in every single file, your compiler does tons more work with the weak symbols approach, but now weak symbols are popular both because they are much simpler to implement and the fact that compilation is usually parallel, while linker is typically not means that walk clock times may even be faster.
by tiagoma on 11/15/18, 12:55 AM
by amelius on 11/14/18, 10:14 PM
by crumbshot on 11/15/18, 1:04 PM
The return value of the `add` function, in most ABI definitions, would be stored in a register. After that, the `main` function may then copy that value to its own space it has reserved on the stack.
This is at odds with the description in the article, which seems to describe `add` passing its return value to `main` via the stack.
(This is assuming no optimizations - all this would most likely be inlined anyway, with no function call.)
by joker3 on 11/14/18, 11:17 PM
by roel_v on 11/15/18, 8:34 AM
I almost sort of get what the author means here but then I don't really. I mean, there is no 'state' for the compiler that is modified by precompiler directives, so this is probably an analogy or simplification he's making here, but I don't really understand how he gets to the mental image of 'compiler state'. Why not just say it like it is: the preprocessor generates long-assed .i (or whatever) 'files' in memory before the actual compiler compiles them, the content of which can be different between compilation units, because preprocessor preconditions might vary between compilation units?
by marco_craveiro on 11/15/18, 9:51 AM
In fact, ideally you'd even generate all binaries for a project in one go but that may be taking it a step too far :-)
At any rate, I searched google scholar for any experience reports on this and found nothing. It must have a more technical name I guess...
by Const-me on 11/15/18, 11:32 AM
VC++ calls that thing “Link-time Code Generation”: https://docs.microsoft.com/en-us/cpp/build/reference/ltcg-li...
LLVM calls it “Link Time Optimization”, pretty similar: http://llvm.org/docs/LinkTimeOptimization.html
by leni536 on 11/15/18, 10:00 AM
by IloveHN84 on 11/15/18, 12:03 PM
There are too much Interests and the standardization would kill many of them