ego*_*or7 5 c c++ cross-platform environment-variables
我在OSX和Windows Vista中使用以下代码:
#include <stdio.h>
#include <string.h>
extern char **environ;
int
main(int argc, char **argv)
{
int i;
for (i = 0; environ[i] != NULL; i++)
{
printf("var = %s - %d\n", environ[i], (int)strlen(environ[i]));
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在OSX上,使用cc,在Windows上进行编译-在Windows SDK 7.1中使用“ cl”进行编译(可重新分发软件包:Microsoft Visual C ++ 2010)。
我在两个操作系统中都用俄语定义了相同的ENV变量:MY_ENV =“俄语字母在这里”。弦长相差约2倍。
我打算使用此长度,malloc并希望它们相同。如何以CRT方式正确获得相同的长度?