You are not logged in.
Pages: 1
I just started writing C and run into a problem which I've run into before but never really found an answer to:
I've seen standard headers included in 2 forms:
<stdio> or <stdio.h>
Running GCC with no options fails to find the file if there's no .h. But I previously wrote a medium-ish project in C++ using Qmake to generate Makefiles and it worked fine without the .h.
What is going on here? Does leaving out the extension require some libraries that GCC doesn't use by default but the generated Makefile includes?
The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github
Offline
I've never heard of including <stdio>; perhaps you're misremembering <cstdio>-style (the proper way to include system headers in C++, ie. with g++) vs <stdio.h>-style (C/gcc)? In C++ system headers tend to lack an extension (ie. #include <cstring>, #include <vector>, etc.), however the C standard headers are named with a 'c' prefix as well as lacking the '.h' suffix under complaint C++ compilers. I truly doubt you've ever seen an included header precisely named as '<stdio>'.
Last edited by bremac (2009-07-15 21:50:29)
Offline
Hi Basu!
In C you have to put the file extension on the #include directive, but in C++ you can omit it, since there isn't a standard for those files.
You could have iostream, iostream.h or iostream.hpp.
Google around, and you'll find better info
Cheers,
Quetzy
ZzZz...
Offline
In C you have to put the file extension on the #include directive, but in C++ you can omit it, since there isn't a standard for those files.
You could have iostream, iostream.h or iostream.hpp.
Actually, that's not quite correct. The standard C++ headers lack extensions on the filesystem instead of simply allowing them to be elided, and must be correctly named as such - thus including 'iostream.hpp' or 'iostream.h' will not work.
Offline
Hi bremac, you're probably right. I didn't think that C and C++ would be different in that regard, but now that you mention it, it does make sense. People tend to use C and C++ together so much that the differences can often be forgotten. Thanks for clearing that up for me.
The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github
Offline
Pages: 1