#pragma data_seg("Share")
volatile int g_nFirst = 0;
int g_nSecond; //注意这里没有初始化,不能放入共享区
#pragma data_seg()
__declspec(allocate("Share")) int g_nThird = 0; //通过__declspec(allocate放入共享区
__declspec(allocate("Share")) int g_nFouth; //可以不进行初始化放入
#pragma comment(linker, "/Section:Share,RWS") //一定要 加上这句, R表示可读, W可写,S共享
int _tmain(int argc, _TCHAR* argv[])
{
g_nFirst++;
if (g_nSecond < 0)
{
g_nSecond = 0;
}
else
{
g_nSecond++;
}
g_nThird++;
if (g_nFouth < 0)
{
g_nFouth = 0;
}
else
{
g_nFouth++;
}
printf("%d, %d, %d, %d", g_nFirst, g_nSecond, g_nThird, g_nFouth);
getchar();
return 0;
}