6 ms·
Wrt "the first line loads the stdio.h function library, which provides the printf() function", you're right, "loading a library" is not clear and, what's worse,
by tragomaskhalos 6y ago
Wrt "the first line loads the stdio.h function library, which provides the printf() function", you're right, "loading a library" is not clear and, what's worse, is actively misleading as actually we're just telling the compiler that there is a function somewhere called printf that will get "loaded" (linked) later on. I remember that this was one of the things that confused me most about C when I learned it.
- tsjq 6y ago>that this was one of the things that confused me most about C when I learned it. absolutely same, me too. and, there was no good websites / videos on the web back then.
- avar 6y agoWe're really just telling the compiler to find a file called stdio.h and act as though its contents were included at that part in our program. Whether the full function is there or linked later is a matter of implementation (some headers have full functions, typically trivial "inline" functions). I can't remember what the standard says via the stdlib, but in general a library you load later on may not have all/some of those functions, but as long as you didn't use them you'll be fine (just as with a redundant forward declaration you yourself did). And finally the whole "linking" part of C is mostly just a widespread convention, not something that the standard really dictates. See section 6.2.2 [1] for the brief words on it mainly to do with "static"/"extern". But the whole "compile" -> "link" (to some existing .so/.a) -> "program" is all implementation defined. 1. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
- pjc50 6y agoYes, one of the confusing things for C newbies is the difference between "works this way on almost all implementations you are likely to encounter" and "actually part of the language". Both provide great opportunities for either the compiler or stackexchange answerers to make the newbie feel inadequate.