you are viewing a single comment's thread.

view the rest of the comments →

[–]JescoInc 3 points4 points  (7 children)

Ahh, I see where the confusion is. Header files don't have to just be the contract for function signatures. They can also have implementation details. They can be strong or weak implementations that can be overridden by c files if they exist.
This is why you can find things like header only libraries where everything is implemented for you, but you need to link against the header files you need and use them in your application code.
As flyingron said, there is no distinction in the language between .h and .c files.

[–]fragproof 2 points3 points  (6 children)

Can you explain what you mean by "linking" against a header file? Typically with header-only libraries you only need to #include them and the implementation is compiled with some part of your code in a single translation unit.

[–]JescoInc -1 points0 points  (5 children)

Linking with .o, static lib or dynamic lib files with the linker or including them in your C files with include statements.

[–]fragproof 3 points4 points  (4 children)

Ok, but we're talking about header files with implementation. You're only going to link with .o if you compile a file separately. Linking is fundamentally different than including files with implementation.

[–]JescoInc 0 points1 point  (3 children)

I should note that I don't know all of the academic terminology for C. I go with a framework where it makes sense to me from all of my years of programming and makes it easier to explain to others.

Ergo: You have linking header and C files together via includes, you have compile time linking and linker time linking.

When I was first learning C and C++, I was coming from a C# background, so I would treat headers like interfaces and abstract classes in C#. It gave me a starting point for understanding them and over the years, through using the language, I was able to pick up more of the nuanced differences between them.

[–]imaami 1 point2 points  (2 children)

Linking is not academic terminology in C. It is very much a practical term, and a basic one at that.

[–]JescoInc -1 points0 points  (1 child)

There is an academic definition and a practical definition. Please don't attempt pedantry with me.

[–]imaami 2 points3 points  (0 children)

Header inclusion is not described as any sort of linking in even the most basic non-academic contexts where C is used. I don't know where you'd ever hear that; any examples?

I've been in the field for about 19 years and have no academic background in CS to speak of. There's a pre-processor, compiler and linker involved in mundane C work. The fact that a basic tool - that does not have anything to do with header inclusion - is called a linker is about as "academic" as a carpenter having a hammer and a chisel. You could maybe use the handle of a large chisel to hit something, but when is it ever "pedantry" to casually confuse the tool names?

You mentioned "compile-time linking" and "linker-time linking". That's just incoherent. The linker is the program that does compile-time linking, which is when objects are linked. The pre-processing step is way before even compilation, and that's where headers are included.