namespace and include

This is a discussion on namespace and include within the C++ Programming forums, part of the General Programming Boards category; Is it safe to do this? Code: namespace std { #include "math.h" } Thanks in advance....

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    namespace and include

    Is it safe to do this?
    Code:
    namespace std {
    #include "math.h"
    }
    Thanks in advance.
    Last edited by audinue; 08-10-2009 at 11:46 AM.
    Just GET it OFF out my mind!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Quote Originally Posted by audinue
    Is it safe to do this?
    Adding declarations or definitions to the std namespace (or namespaces inside of it), other than certain template specialisations, results in undefined behaviour. Just #include <cmath> instead.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    However cmath's round, etc isn't std.
    Just GET it OFF out my mind!!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Quote Originally Posted by audinue
    However cmath's round, etc isn't std.
    hmm... that is true. It looks like what C99 added to <math.h> will be included in the next version of the C++ standard for <cmath>, but for now you should accept that they are not in the std namespace.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    N.. Next version.. (>.<)
    Just GET it OFF out my mind!!

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    Ah well, make a hack. Make your "manual" std namespace and fill it in with the missing prototypes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VC++ release exe exits immediately after execution
    By nocturna_gr in forum Windows Programming
    Replies: 6
    Last Post: 02-09-2008, 04:26 AM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09:08 PM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 12:21 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21