Wats the problem in this Prog???

Thread Solved
Reply

Join Date: Aug 2008
Posts: 42
Reputation: abhisdm is an unknown quantity at this point 
Solved Threads: 4
abhisdm abhisdm is offline Offline
Light Poster

Wats the problem in this Prog???

 
0
  #1
Aug 3rd, 2008
I'm getting an error msg as Type mismatch in redeclaration of 'putw' for the following code... Can anyone suggest the reason for this???

  1. #include<stdio.h>
  2. union pw{
  3. short int i;
  4. char ch[2];
  5. };
  6. int putw(short int num, FILE *fp);
  7. int main()
  8. {
  9. FILE *fp;
  10. fp=fopen("test.tmp","wb+");
  11. putw(1000,fp);
  12. fclose(fp);
  13. return 0;
  14. }
  15. int putw(short int num, FILE *fp)
  16. {
  17. union pw word;
  18. word.i=num;
  19. putc(word.ch[0],fp);
  20. return putc(word.ch[1],fp);
  21. }
Last edited by Tekmaven; Aug 4th, 2008 at 6:30 am. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,002
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 172
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Wats the problem in this Prog???

 
0
  #2
Aug 4th, 2008
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.
Last edited by Aia; Aug 4th, 2008 at 12:12 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 42
Reputation: abhisdm is an unknown quantity at this point 
Solved Threads: 4
abhisdm abhisdm is offline Offline
Light Poster

Re: Wats the problem in this Prog???

 
0
  #3
Aug 4th, 2008
@ 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???
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,002
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 172
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Wats the problem in this Prog???

 
0
  #4
Aug 4th, 2008
>Does that cause a problem???
There can not be two functions named with the same identifier. Even if they both do the same.
Last edited by Aia; Aug 4th, 2008 at 1:08 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Wats the problem in this Prog???

 
0
  #5
Aug 4th, 2008
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...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC