Sunday, July 12, 2009

What will happen if use <#include stdio.h> two times in my C program?

if i use like %26lt;#include stdio.h%26gt;


%26lt;#include stdio.h%26gt;


or any header file what will happen?

What will happen if use %26lt;#include stdio.h%26gt; two times in my C program?
Nothing at all.





Most header files have what's called include guards to deal with this very situation.





Even if you don't directly include stdio.h twice, some other include file you have might itself include stdio.h. You would still get double include.





Header files handle this with the macro preporcessor:





//stdio.h


#Ifndef STDIO_INCLUDED


#define STDIO_INCLUDED


// regular header file stuff goes here


#endif





The first time stdio.h is included, STDIO_INCLUDED will not be defined. The preprocessor then defines STDIO_INCLUDED and uses all the header declarations. The second time it is included STDIO_INCLUDED is already defined. All the text between the #ifdef and the #endif is ignored.
Reply:your code increases by one line !
Reply:nothing for this example, because safeguards are taken usually, but if you get 112 suchAndsuch is already defined errors, that's what causes them





if you write your own header files and choose not to safeguard by wrapping them in





#ifndef filename_h


#define filename_h


#endif





then you can cause problems, it's EXACTLY the same as if you'd just typed it in twice.





PS you don't need to ask us what it'll do, you can just try it! Be Bold.
Reply:nothing happens but you statement is wrong this is the correct one


#include%26lt;stdio.h%26gt;





its only a library
Reply:nothing.. its a command to call libraries? for your defined program..


No comments:

Post a Comment