-
July 27th, 2013, 02:36 PM
#1
Why there is not any compiler errors?
Here is code,
Code:
void foo(int x);
void foo(int x);
int main()
{
return 0;
}
I would expect that there is compiler error for multiple definitions of function foo. But it turns out to be just fine. Why? Thanks.
-
July 27th, 2013, 02:52 PM
#2
Re: Why there is not any compiler errors?
There are not the definitions but declarations.
Try to define (implement) this function.
Victor Nijegorodov
-
August 6th, 2013, 02:54 PM
#3
Re: Why there is not any compiler errors?
Basically you're declaring the same function and not using it. Here's what the build process will "say" for your code (comments):
Code:
void foo(int x); // there is a function named foo
void foo(int x); // there is a function named foo (I already know that, but it doesn't matter)
int main()
{
// ok... do nothing
return 0;
}
// the function foo was never used, so I don't need anything more
If you had called foo in main (say foo(42), there would have been a linker error.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|