Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > #include <cstdio> and #include <stdio.h> in the same file!?

Reply
Thread Tools

#include <cstdio> and #include <stdio.h> in the same file!?

 
 
james.d.mclaughlin@gmail.com
Guest
Posts: n/a
 
      01-22-2013
I was having a look through the header files for a SAT-solver that I neededto work out how to use, and which for some reason seemed to be using a lotof the C versions of the headers (<stdlib.h> instead of <cstdlib> for instance) alongside C++ headers such as <algorithm>.

Which is how I encountered this:

#include <cstdio>
#include <string.h>
#include <stdio.h>

Does anyone know of any reason why someone would want to #include both stdio.h and cstdio in the same file? More importantly, are there any potential pitfalls to doing this? If there are, can I just fix them by commenting outthe line with stdio.h?

A slightly less important question as well - does anyone know of any reasonnot to change <string.h> to <cstring> in the above? I can easily go through the file putting std:: before function names and the like.

Many thanks,

James McLaughlin.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-22-2013
On 1/22/2013 11:40 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I was having a look through the header files for a SAT-solver that I needed to work out how to use, and which for some reason seemed to be using a lot of the C versions of the headers (<stdlib.h> instead of <cstdlib> for instance) alongside C++ headers such as <algorithm>.
>
> Which is how I encountered this:
>
> #include <cstdio>
> #include <string.h>
> #include <stdio.h>
>
> Does anyone know of any reason why someone would want to #include both stdio.h and cstdio in the same file? More importantly, are there any potential pitfalls to doing this? If there are, can I just fix them by commenting out the line with stdio.h?
>
> A slightly less important question as well - does anyone know of any reason not to change <string.h> to <cstring> in the above? I can easily go through the file putting std:: before function names and the like.


Is there a way for you to wrap your lines? For some reason my Tb 17
can't handle your article when quoting...

Anyway...

To answer your question, some C++ library implementations can have the
standard C headers declaring their functions in the global namespace and
the <c..> headers putting the same functions in the 'std' namespace. If
you want to use either 'printf' or 'std:rintf' in your code, you might
want to include both headers to afford yourself that liberty. Often,
however, including the .h version would actually give you both std:: and
:: version of the function, so there would be no need to include both
headers.

As to pitfalls, there could be a [buggy] version of the library where
inclusion of both files could give you ambiguity or even a conflict, but
then you should avoid using that kind of library. Of course, when you
have no choice, you'd work around the issue by only including one or the
other version of the C header.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
james.d.mclaughlin@gmail.com
Guest
Posts: n/a
 
      01-23-2013
> Is there a way for you to wrap your lines? For some reason my Tb 17
> can't handle your article when quoting...


Sorry! I could have sworn Google Groups used to wrap them automatically...

Thanks for the help - but can't really see g++ versions of C library headers
being buggy in the way you describe.

James.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REQ: how to override 2 virtual functions with the same name and same parameter zzppallas@gmail.com C++ 5 02-06-2006 06:54 AM
Local LAN Access - Works for WinXP, No Go For Linux - Same Server,Same Laptop Marc Schwartz Cisco 0 06-18-2005 02:28 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Two PIX on same subnet with same gateway? This Old Man Cisco 4 10-20-2003 07:27 PM
java input and output stream to the same file at the same time? Krick Java 1 08-15-2003 05:55 PM



Advertisments