473,714 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C library in C++ code

For code that was part of the C library, being used in C++, should you
always prefix std::

Specific examples:

std::fopen
std::fclose
std::atexit

Should I include

<cstdio> or <cstdlib>?

g++ 3.4.2 in mingw doesn't seem to care one way or the other. No
warnings or errors are produced even with -W -Wall.

Thanks,

--John Ratliff
Aug 25 '05 #1
5 1407
Ian
John Ratliff wrote:
For code that was part of the C library, being used in C++, should you
always prefix std::

Specific examples:

std::fopen
std::fclose
std::atexit

Should I include

<cstdio> or <cstdlib>?

g++ 3.4.2 in mingw doesn't seem to care one way or the other. No
warnings or errors are produced even with -W -Wall.

One probably includes the other.

Ian
Aug 25 '05 #2
>>
Should I include

<cstdio> or <cstdlib>?

g++ 3.4.2 in mingw doesn't seem to care one way or the other. No
warnings or errors are produced even with -W -Wall.

One probably includes the other.

Ian


Sorry, my post was unclear.

I meant should I include cstdio for std::fclose/std::fopen/std::freopen
and should I include cstdlib for std::atexit.

I wasn't including either, and still no warnings. I was including
iostream, vector, and stdexcept.

--John Ratliff
Aug 25 '05 #3
John Ratliff wrote:
<snip>
I wasn't including either, and still no warnings. I was
including iostream, vector, and stdexcept.

<snip>

In C++, unlike in C, the standard doesn't specify which
header files include each other. So always err on the
safe side and include headers for all functions/classes
you use in a translation unit. Specifically, don't rely
on <iostream> including <cstdio>.

Marc
Aug 25 '05 #4
In message <2dfPe.64649$08 4.1631@attbi_s2 2>, John Ratliff
<us**@example.n et> writes
For code that was part of the C library, being used in C++, should you
always prefix std::
Assuming you're using #include <cxxx> rather than #include <xxx.h>, you
*should*, but some implementations hoist those declarations into the
global namespace willy-nilly, so you might get away without the prefix.
But the first time you try to compile using something that doesn't,
you're in for a lot of editing :-(
Specific examples:

std::fopen
std::fclose
std::atexit

Should I include

<cstdio> or <cstdlib>?
You *should* include both, but in some implementations one will include
the other in any case. Again, you can't rely on this.
g++ 3.4.2 in mingw doesn't seem to care one way or the other. No
warnings or errors are produced even with -W -Wall.


--
Richard Herring
Aug 25 '05 #5
Richard Herring wrote:
In message <2dfPe.64649$08 4.1631@attbi_s2 2>, John Ratliff
<us**@example.n et> writes
For code that was part of the C library, being used in C++, should you
always prefix std::

Assuming you're using #include <cxxx> rather than #include <xxx.h>, you
*should*, but some implementations hoist those declarations into the
global namespace willy-nilly, so you might get away without the prefix.
But the first time you try to compile using something that doesn't,
you're in for a lot of editing :-(

Specific examples:

std::fopen
std::fclose
std::atexit

Should I include

<cstdio> or <cstdlib>?

You *should* include both, but in some implementations one will include
the other in any case. Again, you can't rely on this.
g++ 3.4.2 in mingw doesn't seem to care one way or the other. No
warnings or errors are produced even with -W -Wall.


Thanks, I've done both. And yes, I don't want to rely on any specific
implementation.

--John Ratliff
Aug 25 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2199
by: Simon | last post by:
Hello. I wanna use my dynamic shared library(built with C language) with php script. (PHP version is 4.0.6) So I making a shared library(*.so) in Solaris environment(2.7) and it is successful. Php script can load my library successfully. And Now I port my library to HP(HP-UX 11.0) and IBM(AIX 4.1.3) system.
8
1870
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
3
4266
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is active? Can the setting of LD_LIBRARY_PATH guanrantee that the correct one is executed? 2> In MS-WINDOWS, once a DLL is loaded by one allication, this DLL will be used by the subsequent appication. Does UNIX have the same
1
7100
by: Jim | last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30. When attempted final deployment on Jan 2, 2004 got following messages and errors... I reset everything and tried several times agian. Then erased the setup project and tried to rebuild a new one with the same errors. PLease note... ALL this this code ran perfectly five minutes...
10
2683
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using .NET2003. also, when I do not try to link the fortran library (just to see if that was the cause), it builds the exe without any problems. i don't even know how to begin addressing this problem...any help would be
4
2130
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r) and the Language Objects Library) that I have converted over to C#. It works okay. However, in the C# version, one has to build the class library into the generated application, because I haven't structured this one thing right. I would like to...
87
5131
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for the library, and other resources related to managed strings are available for download from the CERT web site at: http://www.cert.org/secure-coding/managedstring.html
20
5228
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've used various techniques ( loop unrolling, loop jamming...) and tried some matrix libraries : newmat (slow for large matrix) , STL (fast but ..not usefull) , hand coding (brain consuming...), and recently Meschach...
0
4089
by: JosAH | last post by:
Greetings, the last two article parts described the design and implementation of the text Processor which spoonfeeds paragraphs of text to the LibraryBuilder. The latter object organizes, cleans up and stores the text being fed to it. Finally the LibrayBuilder is able to produce a Library which is the topic of this part of the article. Introduction
0
3505
by: JosAH | last post by:
Greetings, welcome back; above we discussed the peripherals of the Library class: loading and saving such an instantiation of it, the BookMark interface and then some. This part of the article discusses the internals of the Library class a bit more. Sections again A previous article part showed how Sections work, i.e. a group Section refers to book Sections, a book Section refers to chapter Sections and the latter refer
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9077
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3159
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.