By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

extern function defination

P: n/a
Hi All,
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;
}
File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));
}
The output of the above program when a.c and b.c are compiled and
linked together is as mentioned bellow .

OUTPUT
=========

10 20 30

Regards
Somenath

Feb 20 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
somenath wrote:
Hi All,
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
[...]
File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));
}
No. If you call a function with the wrong number of arguments, or with
the wrong types of arguments, then the behaviour is undefined, and
then there are no restrictions on what the compiler is allowed to make
your program do whatsoever.

Feb 20 '07 #2

P: n/a
On Feb 20, 10:35 am, "somenath" <somenath...@gmail.comwrote:
Hi All,
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;}

File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));}

The output of the above program when a.c and b.c are compiled and
linked together is as mentioned bellow .

OUTPUT
=========

10 20 30

Regards
Somenath

u r passing 3 parameters, the first two parameters will be assigned to
ur function. so in the function 10 and 20 are printed and then u r
returning x+y i.e. 10+20 so 30 is printed .....

Feb 20 '07 #3

P: n/a
platinum wrote:
On Feb 20, 10:35 am, "somenath" <somenath...@gmail.comwrote:
Hi All,
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;}

File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));}

The output of the above program when a.c and b.c are compiled and
linked together is as mentioned bellow .

OUTPUT
=========

10 20 30

Regards
Somenath


u r passing 3 parameters, the first two parameters will be assigned to
ur function. so in the function 10 and 20 are printed and then u r
returning x+y i.e. 10+20 so 30 is printed .....
This may be true for specific implementations, but it is not true in
general, and causes serious problems on some others.

Feb 20 '07 #4

P: n/a
somenath wrote:
>
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;
}
File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));
}
The output of the above program when a.c and b.c are compiled and
linked together is as mentioned bellow .

OUTPUT
=========

10 20 30
Amazing, since neither source file should compile.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

Feb 20 '07 #5

P: n/a
CBFalconer said:
somenath wrote:
>>
Could any body explain me the ouput of the following code segment

File a.c contains
int f1(int x, int y)
{
printf("%d %d", x, y);
return x+y;
}
File b.c contains
extern int f1();
main()
{
printf(" %d\n", f1(10, 20, 3));
}
The output of the above program when a.c and b.c are compiled and
linked together is as mentioned bellow .

OUTPUT
=========

10 20 30

Amazing, since neither source file should compile.
Why not? It compiles "fine" here, albeit with diagnostic messages that I
would be loathe to ignore. The output, of course, isn't something you'd
want to trust your weight to...

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 20 '07 #6

P: n/a
platinum wrote:

u r passing 3 parameters, the first two parameters will be assigned to
ur function. so in the function 10 and 20 are printed and then u r
returning x+y i.e. 10+20 so 30 is printed .....

Please don't use nonsense abbreviations like "u" and "r". They make
your post difficult to read.


Brian
Feb 20 '07 #7

P: n/a
On Feb 21, 1:37 am, "Default User" <defaultuse...@yahoo.comwrote:
platinum wrote:
u r passing 3 parameters, the first two parameters will be assigned to
ur function. so in the function 10 and 20 are printed and then u r
returning x+y i.e. 10+20 so 30 is printed .....

Please don't use nonsense abbreviations like "u" and "r". They make
your post difficult to read.

Brian
i apologize for using 'u' 'v' , actually this was my first post.
Next time i will take care of that.

Feb 21 '07 #8

P: n/a
platinum wrote:
On Feb 21, 1:37 am, "Default User" <defaultuse...@yahoo.comwrote:
platinum wrote:
u r passing 3 parameters, the first two parameters will be
assigned to ur function. so in the function 10 and 20 are printed
and then u r returning x+y i.e. 10+20 so 30 is printed .....
Please don't use nonsense abbreviations like "u" and "r". They make
your post difficult to read.
i apologize for using 'u' 'v' , actually this was my first post.
Next time i will take care of that.


That would be great, thank you.


Brian
Feb 21 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.