conflict with "string.h" and "time.h"

Discussion in 'Mac Programming' started by freeman-1387, Jan 21, 2011.

  1. freeman-1387 macrumors newbie

    Joined:
    Jan 17, 2011
    #1
    Hi everyone!
    I need some problem. My XCODE project contained 'time.h' and 'string.h' files with my some classes.
    In the compilation process, it became clear that my file has a higher priority compared to a standard "string.h" file. Why ?
    Use #include<string>, including my "string.h" file.

    with "time.h" idential situation.

    how to fix it?
    Thanks
     
  2. willieva macrumors 6502

    Joined:
    Mar 12, 2010
  3. freeman-1387 thread starter macrumors newbie

    Joined:
    Jan 17, 2011
    #3
    This is a known problem? or just me?
    This is the only way out?
     
  4. mydogisbox macrumors member

    Joined:
    Jan 16, 2011
    #4
    Working as expected

    I would actually say this isn't a problem so much as its an intended feature. It's never a good idea to name your projects the same as standard libraries unless you're trying to make your own custom version of them.
     
  5. willieva macrumors 6502

    Joined:
    Mar 12, 2010
    #5
    You could include them like this:
    #include <string.h>
    #include "string.h"

    That would get the system string.h first, then yours.

    Generally, though, it's a bad idea to name your files the same as system files. It makes it difficult for other people to read as they already know what string.h is supposed to mean, and can make debugging code more difficult. Plus you might inadvertently change the behaviour of something in the system string.h.

    If you look at the beginning of /usr/include/string.h, you will see the lines:
    #ifndef _STRING_H_
    #define _STRING_H_

    This is so you won't include the file more than once. All include files should have this when you start having multiple files including your include files.

    These things become important when you start writing larger programs and working with other people.
     
  6. freeman-1387 thread starter macrumors newbie

    Joined:
    Jan 17, 2011
    #6
    Thanks for all!
    I chose way of rename files, and it fix problem.
    Hello from russia !
     

Share This Page