#include vs. -library

P

Phil Carmody

CBFalconer said:
Yes you do. In C99 you need the prototype, else error. In C90 you
need the prototype to mark is as a varargs function. In either
case without the #include your system exhibits undefined behaviour.

What if you foolishly declare it yourself, i.e. having the prototype
inline in your source code without #including the proper header file?

Phil
 
J

James Kuyper

Phil said:
Keith Thompson said:
jameskuyper said:
Phil Carmody wrote:
[...]
The C standard does not require you to use a '-lm' switch in order
to link your C code. In fact, the C standard does not even require
that there is a 'linking' phase. It doesn't even require that there
is any compilation, it's perfectly acceptible to interpret C.
[...]

Well, sort of. Linking is translation phase 8; see C99 5.1.2.2. But
if an implementation can produce the same results without having an
explicit linking phase, that's ok.
Whilst pedantically I should have been corrected,

I retract that. I do not believe there was a flaw in my original
paragraph.

So does that mean that you have returned to the belief that "... the C
standard does not eve require that there is a 'linking' phase." despite
the fact that 5.1.1.2p1 defines phase 8, in which "Library components
are linked ..."?

I'm not trying to argue the point, I'm just checking to make sure I
understand what you're saying.
 
J

James Kuyper

Phil said:
What if you foolishly declare it yourself, i.e. having the prototype
inline in your source code without #including the proper header file?

Chuck is incorrect in stating that the header is required to avoid
undefined behavior. The standard says: " Provided that a library
function can be declared without reference to any type defined in a
header, it is also permissible to declare the function and use it
without including its associated header." (7.1.4p2).

However, this is an error prone way of doing things that has no
compensating advantage.
 
P

Phil Carmody

James Kuyper said:
Phil said:
Keith Thompson said:
Phil Carmody wrote:
[...]
The C standard does not require you to use a '-lm' switch in order
to link your C code. In fact, the C standard does not even require
that there is a 'linking' phase. It doesn't even require that there
is any compilation, it's perfectly acceptible to interpret C.
[...]

Well, sort of. Linking is translation phase 8; see C99 5.1.2.2. But
if an implementation can produce the same results without having an
explicit linking phase, that's ok.
Whilst pedantically I should have been corrected,

I retract that. I do not believe there was a flaw in my original
paragraph.

So does that mean that you have returned to the belief that "... the C
standard does not eve require that there is a 'linking' phase."
despite the fact that 5.1.1.2p1 defines phase 8, in which "Library
components are linked ..."?

I'm not trying to argue the point, I'm just checking to make sure I
understand what you're saying.

I am indeed saying that. I hadn't noticed footnote 5 before.

Phil
 
J

James Kuyper

Phil said:
I am indeed saying that. I hadn't noticed footnote 5 before.

Well, yes, in that sense it doesn't actually require that there be a
separate linkage phase. In that sense, the C standard imposes very few
requirements of any king; they're all subject to the "as if" rule.
However, the standard does require that the compiler behave as-if there
was such a separate phase.

That's what Keith was referring to when he said "But if an
implementation can produce the same results without an explicit linking
phase, that's ok.".
 
K

Keith Thompson

Phil Carmody said:
I am indeed saying that. I hadn't noticed footnote 5 before.

Which says, in C99:

Implementations shall behave as if these separate phases occur,
even though many are typically folded together in practice.

N1256 expands this to:

Implementations shall behave as if these separate phases occur,
even though many are typically folded together in practice. Source
files, translation units, and translated translation units need
not necessarily be stored as files, nor need there be any
one-to-one correspondence between these entities and any external
representation. The description is conceptual only, and does not
specify any particular implementation.

(To be clear, I'm not disagreeing with anyone.)
 
M

Mark Wooding

James Kuyper said:
the C standard imposes very few requirements of any king

Name one king of whom the C standard imposes a requirement! Go on: I
challenge you!

-- [mdw]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top