Force Visual Studio only use standard C ++ and don't use platform specific things

I want to write a cross platform algorithm in C ++ with Visual Studio 2013.

Platform-specific API functions ( _beginThread

, strcpy_s

etc.) can inadvertently be used , and when trying to compile on a Mac, results in errors.

Is there a way to force Visual Studio not to use the platform API (only use standard C ++)?

+3


source to share


1 answer


There are 3 ways to do this to achieve this.



  • Use the #ifdef directive.

    #ifdef _MSC_VER
    strcpy_s(str1, str2);
    #else
    strcpy(str1, str2);
    #endif
    
          

  • Create an alias for strcpy_s

    .

    #ifdef _MSC_VER
    #define strcpy strcpy_s
    #endif
    
          

  • Add _CRT_SECURE_NO_WARNINGS and _SCL_SECURE_NO_WARNINGS to your C ++ preprocessor definition in your Visual Studio project. Only do this if you are 100% sure of what you are doing and using platform agnostic code is fine.

+1


source







All Articles