Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

/usr/include/*.h

45 views
Skip to first unread message

Popping mad

unread,
Nov 15, 2016, 10:29:43 PM11/15/16
to
I am using zlib and it has zlib.h in the /usr/include/ directory on the
system. Why can I not use

#include <zlib>
or
#include <czlib>

to include it in my program. It is not being seen.

Ian Collins

unread,
Nov 15, 2016, 11:25:14 PM11/15/16
to
Because you forgot the ".h"?

--
Ian

Popping mad

unread,
Nov 16, 2016, 12:05:55 AM11/16/16
to
On Wed, 16 Nov 2016 17:25:03 +1300, Ian Collins wrote:


>> to include it in my program. It is not being seen.
>
> Because you forgot the ".h"?

why does it need a .h? Why does it not work like #include <cstdlib>

Ian Collins

unread,
Nov 16, 2016, 12:52:08 AM11/16/16
to
Because that isn't the name of the file!

--
Ian

Melzzzzz

unread,
Nov 16, 2016, 1:38:52 AM11/16/16
to
He doesn't understand what #include preprocessor directive does...

--
press any key to continue or any other to quit

Christian Gollwitzer

unread,
Nov 16, 2016, 5:06:09 AM11/16/16
to
Am 16.11.16 um 04:29 schrieb Popping mad:
The compiler really only looks for the name that you put into the <>.
#include <cstdio> to include #include <stdio.h> in std) only works,
because the C++ library ships with file called "cstdio", which
basically does

namespace std {
#include <stdio.h>
}

There is no magic by which the compiler would derive the .h file from
the extensionless name.

Christia

Popping mad

unread,
Nov 16, 2016, 5:23:44 AM11/16/16
to
On Wed, 16 Nov 2016 11:05:53 +0100, Christian Gollwitzer wrote:

> namespace std {
> #include <stdio.h>
> }
>
> There is no magic by which the compiler would derive the .h file from
> the extensionless name.


that also goes for including the .h which we, by convention do in C but
in C++ we drop the .h from the #includes?


Paavo Helde

unread,
Nov 16, 2016, 6:12:55 AM11/16/16
to
This is not a convention. It's just that C++ standard decided to define
some header files with no filename extension. IIRC the idea was that
these might not be real disk files at all, so a filename extension is
not needed. But in reality typical implementations still have them as
actual disk files.



David Brown

unread,
Nov 16, 2016, 11:15:16 AM11/16/16
to
It has the convenience of making it easy to distinguish standard library
headers and other headers that might be on your compiler's include
paths, and means that the C++ standard library can add new headers
without worrying about conflicts.


Richard

unread,
Nov 17, 2016, 5:58:11 PM11/17/16
to
[Please do not mail me a copy of your followup]

Popping mad <rai...@colition.gov> spake the secret code
<o0gjqr$k40$7...@reader2.panix.com> thusly:

>I am using zlib and it has zlib.h in the /usr/include/ directory on the
>system. Why can I not use
>
>#include <zlib>

Because the header is named zlib.h. The <> vs. "" just changes the
places where the compiler looks for header files. Other than that,
you have to specify the entire name of the header file.

>#include <czlib>

These style of includes, e.g. <cstdlib>, are special include file
names specified by the ISO C++ standard. zlib is not part of the
standard. (One could argue that zlib, not being a standard header
file, should not be installed in /usr/include but somewhere else like
/opt/include or /usr/local/include or whatever.)
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

woodb...@gmail.com

unread,
Nov 17, 2016, 8:52:11 PM11/17/16
to
On Thursday, November 17, 2016 at 4:58:11 PM UTC-6, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> Popping mad <rai...@colition.gov> spake the secret code
> <o0gjqr$k40$7...@reader2.panix.com> thusly:
>
> >I am using zlib and it has zlib.h in the /usr/include/ directory on the
> >system. Why can I not use
> >
> >#include <zlib>
>
> Because the header is named zlib.h. The <> vs. "" just changes the
> places where the compiler looks for header files. Other than that,
> you have to specify the entire name of the header file.
>
> >#include <czlib>
>
> These style of includes, e.g. <cstdlib>, are special include file
> names specified by the ISO C++ standard.

I'm not able to recall who it was that made this point previously,
but someone here said that those special names are a hindrance
in terms of searching. In general I'm not an advocate of uniformity,
but having multiple forms for the names of headers makes it harder
to find things.

And if I remember right, Alf advocated against using those
parallel headers that start with a 'c', like <cstdio>.
I think he considered them to be a failed experiment.


Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net

Robert Wessel

unread,
Nov 17, 2016, 9:20:56 PM11/17/16
to
I'm not sure what searching issues are involved, usually the c*
headers are just a fairly thin wrapper around the *.h headers. There
are some namespace differences, which usually results in a small
amount of code in the c* version.

Juha Nieminen

unread,
Nov 21, 2016, 2:46:19 AM11/21/16
to
Popping mad <rai...@colition.gov> wrote:
> why does it need a .h? Why does it not work like #include <cstdlib>

The compiler has a file named "cstdlib". It does not have a file named "zlib"
or "czlib". If there exists no file with that name, it obviously can't include it.

Juha Nieminen

unread,
Nov 21, 2016, 2:47:54 AM11/21/16
to
Popping mad <rai...@colition.gov> wrote:
> that also goes for including the .h which we, by convention do in C but
> in C++ we drop the .h from the #includes?

The .h was dropped from the standard header *file names*. There is
literally a file named "cstdlib" in your compiler's standard library
directory.
0 new messages