| Start |
|---|
| Understanding Declaration and Definition A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier. These are declarations: A definition actually instantiates/implements this identifier. It's what the linker needs in order to link references to those entities. These are definitions corresponding to the above declarations: A definition can be used in the place of a declaration. However, it must be defined exactly once. If you forget to define something that's been declared and referenced somewhere, then the linker doesn't know what to link references to and complains about a missing symbols. If you define something more than once, then the linker doesn't know which of the definitions to link references to and complains about duplicated symbols. Exception: This exception can be explained using concepts of "Strong symbols vs Weak symbols" (from a linker's perspective) . Please look here (opens new window) ( Slide 22 ) for more explanation. RemarksSource: What is the difference between a definition and a declaration? (opens new window) Source (For weak and strong symbols): https://www.amazon.com/Computer-Systems-Programmers-Perspective-2nd/dp/0136108040/ (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference