On Wed, 22 Aug 2007 09:53:09 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote in comp.lang.c:
Roman Mashak said:
<snip>
Code structure is the following:
my_hdr.h
...
long freq[NR];
long power[NR];
int i, j;
extern void ParseParams(FILE *fd);
------------
my_hdr.c
#include "my_hdr.h"
/* here follows implementation of ParseParams() */
-------------
main.c (main app)
#include "my_hdr.h" /* because I need ParseParams() */
...
What's wrong with this for borland builder? Do I violate standards or
this is "feature" of borland compiler? Gcc is quite happy.
The code is broken, so gcc has no business being happy. Crank on the
warning level handle until it screams with pain.
Actually the program violates a "shall" outside of a constraint
clause, rendering the behavior undefined with no diagnostic required.
C99 6.9 P9:
"An external definition is an external declaration that is also a
definition of a function (other than an inline definition) or an
object. If an identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof operator
whose result is an integer constant), somewhere in the entire program
there shall be exactly one external definition for the identifier;
otherwise, there shall be no more than one."
One possible consequence of this undefined behavior is for the program
to work as though the external object had only been defined once. In
fact this is quite common with tool sets that use linker models based
on a particular 60-year-old language and implement external objects
using common blocks, as long as no more than one of the definitions
has an explicit initializer.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html