DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   Wats the problem in this Prog??? (http://www.daniweb.com/forums/thread138349.html)

abhisdm Aug 3rd, 2008 11:22 pm
Wats the problem in this Prog???
 
I'm getting an error msg as Type mismatch in redeclaration of 'putw' for the following code... Can anyone suggest the reason for this???

#include<stdio.h>
union pw{
short int i;
char ch[2];
};
int putw(short int num, FILE *fp);
int main()
{
  FILE *fp;
  fp=fopen("test.tmp","wb+");
  putw(1000,fp);
  fclose(fp);
  return 0;
}
int putw(short int num, FILE  *fp)
{
union pw word;
word.i=num;
putc(word.ch[0],fp);
return putc(word.ch[1],fp);
}

Aia Aug 4th, 2008 12:09 am
Re: Wats the problem in this Prog???
 
Name putw() to something different like putword(). Most likely there's an implementation of putw() already prototyped in your compiler library.

Please, make sure you use proper tags when you post code next time. Here's how.

abhisdm Aug 4th, 2008 12:53 am
Re: Wats the problem in this Prog???
 
@ AIA
Thanks ....
There existed a function in lib..
But the declaration of function was
int putw(int w, FILE *stream)
the only difference between this and the declaration in prog above is that short int is being used in the putw function...
Does that cause a problem???

Aia Aug 4th, 2008 1:04 am
Re: Wats the problem in this Prog???
 
>Does that cause a problem???
There can not be two functions named with the same identifier. Even if they both do the same.

ArkM Aug 4th, 2008 5:27 am
Re: Wats the problem in this Prog???
 
Moreover, visually identical functions with int and short int arguments have different compiled bodies codes and calling codes too. For example, to pass short int arg the compiler emits "push half-word" CPU instruction but for int arg it emits "load word" instruction...


All times are GMT -4. The time now is 12:07 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC