Week 15 Day 2 - Linker Errors, The Bus
Today we talked about Linker errors for about an hour, and then the bus.
The linker errors talk was inspired by an actual bug caused by one of my header files when used by a student in one of his projects. He included the header file in two .cc files, and this resulted in two definitions of each function existing, which caused a redefinition error in the linker.
There's three keywords that help resolve such linking issues in C++:
1) Inline - which is turned on by default by class member functions. Inline turns a symbol into a weak symbol, which allows multiple copies of it to exist. This is the easiest solution to the problem.
2) Extern - which promises that a variable or function exists "somewhere else". So you can put this in a common header file and then actually put the definition of the variable or function into a .cc file somewhere and link it in.
3) Static - which I didn't talk about in the video, limits a function to only being used within the same file, and won't add a symbol for that function to the symbol table. This will also let you work around the issue of being double included, but a compiler will warn if you make a static function but don't use it, so inline is better.
Second, we talked about Busses, which are common lines for data transmission. (Well, that's the classic definition anyway. Modern busses like PCI-E typically don't share a transmission medium.) You can think of a bus as a piece of copper that a lot of devices are hooked up to. A bus master will connect and disconnect different devices to the bus, so that one device can transmit to any other device attached to the bus.