Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.c++.moderated > #7370

Re: Is <cstdlib> required?

Path csiph.com!feeder.erje.net!2.us.feeder.erje.net!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Tue, 16 Feb 2016 12:40:02 -0600
Return-Path <cppmods@glengoyne.dreamhost.com>
Sender lang-cpp-request@vandevoorde.com
Approved c.l.c.m@bazarov.com
Message-ID <dih4hkFs0mfU1@mid.individual.net> (permalink)
Newsgroups comp.lang.c++.moderated
From Bo Persson <bop@gmb.dk>
Subject Re: Is <cstdlib> required?
Organization unknown
References <aaa44aee-e02a-4be7-a94d-2d4ac57773d3@googlegroups.com>
Content-Type text/plain; charset=windows-1252; format=flowed
X-Original-Date Tue, 16 Feb 2016 18:28:13 +0100
X-Submission-Address lang-cpp-submit@vandevoorde.com
Date Tue, 16 Feb 2016 12:32:26 CST
Lines 39
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-2cCkPotzO7aP9cxKwqZgXjBjrwrwm8gZtKFZcn1oyzaf2RUhAlf4fabtUkhH+JuE3AGUUCIq/1tsyfq!gTzPvYJkYbLFWSZM82cZM4EhyKwOrgJbeyKLWqNyqOHqPys5V1pxeBhGdXo=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2313
Xref csiph.com comp.lang.c++.moderated:7370

Show key headers only | View raw


On 2016-02-16 14:03, Joe Bentley wrote:
>
> Is the <cstdlib> header file required?  I have noticed that in some
> implementations it appears to be automatically included.  Maybe it's
picked
> up by <iostream> or some other common header file, but I can't find any
> reference on this.  Does the "standard" have anything to say on its
> inclusion by other header files?
>
>

You should include the headers of the things you use. That's the simple 
rule.

The standard says that any C++ header may include any other C++ header, 
as needed. Relying on one header including some other header makes your 
code non-portable, as the next compiler might include another set of 
headers.

For <iostream> in particular, the standard makes an exception and 
explicitly requires these includes:

#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>

Whether any of those in turn includes <cstdlib> is not specified.



     Bo Persson


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Back to comp.lang.c++.moderated | Previous | NextPrevious in thread | Find similar


Thread

Is <cstdlib> required? Joe Bentley <joe.foxhound@googlemail.com> - 2016-02-16 07:03 -0600
  Re: Is <cstdlib> required? Bo Persson <bop@gmb.dk> - 2016-02-16 12:32 -0600

csiph-web