extern function defination

S

somenath

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
 
G

Guest

somenath said:
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.
 
P

platinum

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 .....
 
G

Guest

platinum said:
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.
 
C

CBFalconer

somenath said:
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
 
R

Richard Heathfield

CBFalconer said:
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...
 
D

Default User

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
 
P

platinum

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.
 

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

Similar Threads

extern 29
Why struct not globally changed in function? 1
Question about extern keyword 7
extern int *a , int a[10] 6
Why no compilation error. 14
extern pointers. 5
linking problem? | extern keyword 6
Use of extern 2

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top