您的位置:首页 > 其它

通过#pragma data_seg共享数据

2009-04-06 09:39 453 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: