Thread: Why is std:: not needed in front of C functions?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    956
    Quote Originally Posted by john.c View Post
    I wonder if it's just a concession to ease compiler implementation.
    I imagine it's more to make it easier for people to migrate from C to C++. Most valid C programs can compile as C++ without any changes.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Quote Originally Posted by christop View Post
    I imagine it's more to make it easier for people to migrate from C to C++. Most valid C programs can compile as C++ without any changes.
    That can't be the reason since including a C header as <stdlib.h> is guaranteed to dump the identifiers into the global namespace (but can additionally put them in std). Including it as <cstdlib> is guaranteed to put the identifiers in std (but can additionally dump them globally).
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    956
    Quote Originally Posted by john.c View Post
    That can't be the reason since including a C header as <stdlib.h> is guaranteed to dump the identifiers into the global namespace (but can additionally put them in std). Including it as <cstdlib> is guaranteed to put the identifiers in std (but can additionally dump them globally).
    Oh, I see what you mean. I must have skimmed the part about including cstdlib vs stdlib.h. In that case, yes, it might be to ease compiler implementation, or it could be written that way in the standard because existing compilers do it that way. It's basically a warning to the application writer that those function names might be defined at the global namespace, so the application writer cannot use those function names.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-14-2013, 04:31 AM
  2. Functions,factorials asap help needed! :(
    By Solarwin in forum C Programming
    Replies: 13
    Last Post: 12-04-2012, 01:00 PM
  3. Replies: 9
    Last Post: 10-08-2012, 06:48 AM
  4. Add to Front, Remove from Front, Traverse
    By Brandon Smith in forum C Programming
    Replies: 9
    Last Post: 04-10-2012, 03:26 PM
  5. Explanation of functions needed.
    By JOZZY& Wakko in forum C Programming
    Replies: 4
    Last Post: 12-16-2009, 12:09 PM

Tags for this Thread