How come I can use strcmp without including <cstring> ?

This is a discussion on How come I can use strcmp without including <cstring> ? within the C++ Programming forums, part of the General Programming Boards category; Somehow my program still runs, eventhough my gut tells me that it shouldn't. I've used the function strcmp and strcpy ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    197

    How come I can use strcmp without including <cstring> ?

    Somehow my program still runs, eventhough my gut tells me that it shouldn't.

    I've used the function strcmp and strcpy without using <cstring>. I've also used the functions atof, atol, and atoi with using <cstdlib>. Are these function included in <iostream> ? Or is this simply because GCC does not adhere to some standard that it is suppose to?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Some other (standard) header could have included those other headers.
    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
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Such behaviour is non-portable, however. Make sure you always include the right headers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    does std:: pair apear in any other library besides utility? Just asking

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    It will almost certainly appear in <map> and <multimap>, since maps use pairs in their member function arguments and return types. I'm not sure if that is guaranteed by the standard explicitly though.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's not. The standard guarantees that the things that are listed for that header appear. Nothing else.

    As long as the standard headers are real files, there is no way around it. (I think. It might be that std:air only appears in references, which would mean a forward declaration would suffice on a compiler that supports extern templates.) But the standard doesn't even guarantee that: the compiler could just as well use those names as triggers to make the symbols available and not include the file.

    However, what I said above is subject to some dispute. For example, by my philosophy, this program is not standards-conformant:
    Code:
    #include <iostream>
    
    int main()
    {
      std::cout << "Hello, World!" << std::endl;
    }
    The reason is that std::endl is part of <ostream>, not <iostream>. It's not available.

    Some people on c.l.c++.m and c.s.c++ argue that the above program should be compliant. Some disagree. In the end, all current compilers accept it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fucntion returns -1, Why?
    By Taper in forum C Programming
    Replies: 16
    Last Post: 12-08-2008, 05:30 PM
  2. help with switch statement
    By agentsmith in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 04:02 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 11:04 AM

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