function declared, but not defined

  • Follow


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,
0
Reply Tagore 7/23/2010 12:21:47 AM

On 07/23/10 12:21 PM, Tagore wrote:
> 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?

-- 
Ian Collins
0
Reply Ian 7/23/2010 12:24:05 AM


No, I am not calling it, but intend to call it later.

On Jul 23, 5:24=A0am, Ian Collins <ian-n...@hotmail.com> wrote:
> On 07/23/10 12:21 PM, Tagore wrote:
>
> > 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?
>
> --
> Ian Collins

0
Reply Tagore 7/23/2010 12:27:21 AM

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

[please don't top-post]

> On Jul 23, 5:24 am, Ian Collins<ian-n...@hotmail.com>  wrote:
>> On 07/23/10 12:21 PM, Tagore wrote:
>>
>>> 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?
>>
 > No, I am not calling it, but intend to call it later.

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

-- 
Ian Collins
0
Reply Ian 7/23/2010 12:56:48 AM

On 23 Jul., 02:21, Tagore wrote:
>
> 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
0
Reply Sebastian 7/23/2010 12:11:58 PM

Tagore wrote:
> 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.

-- 
Best regards,
Andrey Tarasevich
0
Reply Andrey 7/23/2010 6:11:36 PM

Sebastian <s.gesemann@gmail.com> writes:

> On 23 Jul., 02:21, Tagore wrote:
>>
>> 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

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>
-- 
Ben.
0
Reply Ben 7/23/2010 7:01:17 PM

On 23 Jul., 21:01, Ben Bacarisse wrote:
> Sebastian <s.gesem...@gmail.com> writes:
> > On 23 Jul., 02:21, Tagore wrote:
>
> >> 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."
>
> > =A0 struct foo; =A0 =A0 =A0 =A0 =A0 =A0 // <-- declaration (incomplete =
type)
> > =A0 struct foo { int j; }; =A0// <-- definition
>
> Actually that's debatable. =A0The syntax for the whole thing ({}s and
> all) is a "struct-declaration" and some of the examples in the
> standard say things like:
>
> =A0 After the further declaration:
> =A0 =A0 =A0 struct ss { int n; };
>
> I'd say its not wrong to call it either. =A0Definitions 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
0
Reply s.gesemann (661) 7/26/2010 9:27:51 AM

7 Replies
430 Views

(page loaded in 0.148 seconds)

Similiar Articles:













7/25/2012 12:41:50 AM


Reply: