function declared, but not defined

T

Tagore

Hi,

I was declaring a function as extern in one of my module, but I was
not declaring it anywhere. I am still not getting any linking error.
Is it my Compiler deficiency?

Thanks,
 
I

Ian Collins

Hi,

I was declaring a function as extern in one of my module, but I was
not declaring it anywhere. I am still not getting any linking error.

Are you calling it?
 
I

Ian Collins

On 07/23/10 12:27 PM, Tagore wrote:

[please don't top-post]
> No, I am not calling it, but intend to call it later.

Well then, there's nothing to complain about until you do!
 
S

Sebastian

I was declaring a function as extern in one of my module, but I was
not declaring it anywhere.

You mean "not _defining_ it anywhere."

struct foo; // <-- declaration (incomplete type)
struct foo { int j; }; // <-- definition

int bar(int a, int b); // <-- declaration
int bar(int a, int b) { // <-- definition
return a+b;
}

Make sure you understand the difference.

Cheers!
SG
 
A

Andrey Tarasevich

Tagore said:
I was declaring a function as extern in one of my module, but I was
not declaring it anywhere. I am still not getting any linking error.

Huh? Did you mean "not defining it anywhere"?
Is it my Compiler deficiency?

No. The definition is only required when the function is _used_ in an
expression. If it is not used, there's no requirement to define it.
 
B

Ben Bacarisse

Sebastian said:
You mean "not _defining_ it anywhere."

struct foo; // <-- declaration (incomplete type)
struct foo { int j; }; // <-- definition

Actually that's debatable. The syntax for the whole thing ({}s and all)
is a "struct-declaration" and some of the examples in the standard say
things like:

After the further declaration:
struct ss { int n; };

I'd say its not wrong to call it either. Definitions always act as
declarations (at least I can't think of a case where they don't) and
the above does define a structure in the ordinary English sense of the
word.
int bar(int a, int b); // <-- declaration
int bar(int a, int b) { // <-- definition
return a+b;
}

It's worth bearing in mind that the function definition also acts as a
declaration of it (and in this case, both are serve as prototypes as
well).

<snip>
 
S

Sebastian

Actually that's debatable.  The syntax for the whole thing ({}s and
all) is a "struct-declaration" and some of the examples in the
standard say things like:

  After the further declaration:
      struct ss { int n; };

I'd say its not wrong to call it either.  Definitions always act as
declarations (at least I can't think of a case where they don't) and
the above does define a structure in the ordinary English sense of
the word.

Seems like this is another case where the C++ terminology differs from
the C terminology.

Cheers!
SG
 

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,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top