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);
}

Recommended Answers

All 4 Replies

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.

@ 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???

>Does that cause a problem???
There can not be two functions named with the same identifier. Even if they both do the same.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.