Thread: header file question

  1. #1
    Registered User gell10's Avatar
    Join Date
    Jul 2003
    Posts
    46

    header file question

    hi I was just wondering why

    #include <stdio.h>

    is being replaced by

    #include <stdio>

    I was just wondering what the point of it was. Do people find it easier to skip the .h part? If anyone can answer my question thank you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    No, it's replaced by
    #include <cstdio>

    It is (I think) primarily to do with namespaces.

    It's all part of the new C++ standard way of doing things.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User gell10's Avatar
    Join Date
    Jul 2003
    Posts
    46
    is there a reason why though? I was just wondering

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Is the question:
    1. Is there a reason why the people that made the C++ standard made new header files without the .h?
    or
    2. Is there a reason why programmers use the new header files without the .h?

    My answers:
    1. Like Salem said, they wanted to redesign the standard library headers a little, so instead of changing how they were supposed to be implemented in the old filenames, they followed a new header file naming convention. As far as more detailed reasons on why they did this, I can't think of any specific places to get those answers right now.
    or
    2. Programmers use the files without the '.h' because they are the currently preferred headers according to the standard. The old standard C library headers are deprecated (they may not work on new compilers some time in the future). There are also old C++ library headers (like iostream.h) that aren't standard at all, so they might not work right now with a compiler that is strict about following the standard (most current compilers do allow the old headers for compatibility with old code).

  5. #5
    Registered User gell10's Avatar
    Join Date
    Jul 2003
    Posts
    46
    Why do they make the old code not standard anymore, is it not as efficient as the new header files? They should only add on to the amount of header files. Like a english dictionary, it only gets larger with time.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Originally posted by gell10
    Why do they make the old code not standard anymore, is it not as efficient as the new header files? They should only add on to the amount of header files. Like a english dictionary, it only gets larger with time.
    Because they changed the way they do things. The language itself was poorly designed, they improved it, and eventually the old way is no longer legal.

    They give a lot of time, many years, before they remove things, though. But sometimes, there is little choice.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by gell10
    Why do they make the old code not standard anymore
    They didn't, at least not for the older C library headers such as <stdio.h>, <stdlib.h> etc. Those were inherited from standard C, and as such they're standard C++. Every conforming C++ compiler provides them. They're deprecated, so support for them *may* be removed from a future version of the standard, but for now they are indeed standard C++ libraries. That said, you should prefer the newer C++ versions such as <cstdio>, <cstdlib> etc unless you have a good reason not to (e.g. backwards compatibility, maintaining old code).

    Headers such as <iostream.h> etc were never 'standard' in the first place until they were standardised by ISO in the C++ standard, as <iostream> etc. Many compilers still support the older versions for backwards compatibility, but otherwise you should prefer to use the standard headers.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Omnius, standard C++ is not just a superset of standard C. This is especially true of C99, but even before, not all valid C code was valid C++ code as well.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by Cat
    Omnius, standard C++ is not just a superset of standard C. This is especially true of C99, but even before, not all valid C code was valid C++ code as well.
    I'm well aware of that. Which part of my post were you disagreeing with?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. header file question
    By unanimous in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 08:15 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM