В то время как я пытался использовать Visual Studio 2010 для компиляции программы MFC, которая использовала библиотеку, написанную в Visual Studio 2003. Неудивительно, что я получил кучу предупреждений об устаревании и использовании защищенных версий различных строковых функций.
Затем я обновил соответствующие функции в библиотеке, чтобы использовать защищенные функции и скомпилирован.
Позже я попытался скомпилировать его еще раз на другой системе с помощью Visual Studio 2003 и получил отвращение к отсутствующим защищенным функциям.
Я решил создать гибридный подход, который позволил бы мне скомпилировать программы, которые используют библиотеку в любой среде, используя защищенные функции, если они доступны, а если нет, накладывая их на старые.
Сначала я решил проверить каждую функцию, чтобы увидеть, существует ли безопасная версия, но она не работает и требует отдельной работы для каждой функции:
#ifndef strcpy_s
#define strcpy_s(a,b,c) strcpy(a,c)
#endif
#ifndef strcat_s
#define strcat_s(a,b,c) strcat(a,c)
#endif
…
Итак, что я пытаюсь выяснить, это способ определить, существуют ли защищенные функции. Я знаю, что они были представлены в Visual Studio 2005, но есть ли #define
или что-то, что можно использовать следующим образом?
#ifndef SECURE_FUNCTIONS // or #ifdef VS_VER_2005, #if (VS_VER >= 0x2005) etc.
#define strcpy_s(a,b,c) strcpy(a,c)
#define strcat_s(a,b,c) strcat(a,c)
…
#endif
Я проверил crtdefs.h
, но ничего полезного не нашел.