静态库和动态库里的全局变量(或类的静态成员变量)共享和独立的问题

上传者: guggy | 上传时间: 2021-04-28 13:04:06 | 文件大小: 82KB | 文件类型: RAR
测试代码说明以下两个问题: 1. 工程中包含静态库A,动态库B,可执行程序C。C依赖于A和B,而B依赖于A。在A中定义有全局变量X(或类的静态成员变量),则在动态库B中访问的X,与可执行程序C中访问的X是同一个变量还是两个不同的变量? 答案:是两个不同的变量。 2. 工程中包含动态库A,动态库B,可执行程序C。C依赖于A和B,而B依赖于A。在A中定义有全局变量X(或类的静态成员变量),则在动态库B中访问的X,与可执行程序C中访问的X是同一个变量还是两个不同的变量?(注:所有库都在同一进程中使用) 答案:是共享同一个变量。即:在A是动态库的这种情况下,B和C访问到的X是同一变量。 博文地址:http://blog.csdn.net/guggy/article/details/8136325 或即时记:http://www.livelog.cn/bbs/viewthread.php?tid=16

文件下载

资源详情

[{"title":"( 72 个子文件 82KB ) 静态库和动态库里的全局变量(或类的静态成员变量)共享和独立的问题","children":[{"title":"LibraryTest","children":[{"title":"StaticTest","children":[{"title":"TestDlg","children":[{"title":"TestDlg.rc <span style='color:#111;'> 5.51KB </span>","children":null,"spread":false},{"title":"TestDlg.plg <span style='color:#111;'> 1.16KB </span>","children":null,"spread":false},{"title":"res","children":[{"title":"TestDlg.ico <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false},{"title":"TestDlg.rc2 <span style='color:#111;'> 399B </span>","children":null,"spread":false}],"spread":true},{"title":"TestDlg.aps <span style='color:#111;'> 20.38KB </span>","children":null,"spread":false},{"title":"TestDlg.dsw <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false},{"title":"TestDlg.clw <span style='color:#111;'> 1.56KB </span>","children":null,"spread":false},{"title":"TestDlg.dsp <span style='color:#111;'> 4.13KB </span>","children":null,"spread":false},{"title":"TestDlg.opt <span style='color:#111;'> 64.00KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 209B </span>","children":null,"spread":false},{"title":"resource.h <span style='color:#111;'> 685B </span>","children":null,"spread":false},{"title":"TestDlgDlg.cpp <span style='color:#111;'> 4.29KB </span>","children":null,"spread":false},{"title":"TestDlg.cpp <span style='color:#111;'> 2.03KB </span>","children":null,"spread":false},{"title":"TestDlg.h <span style='color:#111;'> 1.30KB </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 1.03KB </span>","children":null,"spread":false},{"title":"TestDlg.ncb <span style='color:#111;'> 81.00KB </span>","children":null,"spread":false},{"title":"TestDlgDlg.h <span style='color:#111;'> 1.35KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 3.51KB </span>","children":null,"spread":false}],"spread":false},{"title":"B","children":[{"title":"B.def <span style='color:#111;'> 22B </span>","children":null,"spread":false},{"title":"B.dsw <span style='color:#111;'> 525B </span>","children":null,"spread":false},{"title":"B.dsp <span style='color:#111;'> 4.22KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 288B </span>","children":null,"spread":false},{"title":"B.cpp <span style='color:#111;'> 339B </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 802B </span>","children":null,"spread":false},{"title":"B.ncb <span style='color:#111;'> 33.00KB </span>","children":null,"spread":false},{"title":"B.plg <span style='color:#111;'> 3.15KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 1.55KB </span>","children":null,"spread":false},{"title":"B.opt <span style='color:#111;'> 47.50KB </span>","children":null,"spread":false}],"spread":true},{"title":"Bin","children":null,"spread":false},{"title":"A","children":[{"title":"A.plg <span style='color:#111;'> 236B </span>","children":null,"spread":false},{"title":"A.cpp <span style='color:#111;'> 93B </span>","children":null,"spread":false},{"title":"A.opt <span style='color:#111;'> 47.50KB </span>","children":null,"spread":false},{"title":"A.dsp <span style='color:#111;'> 2.71KB </span>","children":null,"spread":false},{"title":"A.ncb <span style='color:#111;'> 33.00KB </span>","children":null,"spread":false},{"title":"A.dsw <span style='color:#111;'> 525B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"DllTest","children":[{"title":"TestDlg","children":[{"title":"TestDlg.rc <span style='color:#111;'> 5.51KB </span>","children":null,"spread":false},{"title":"TestDlg.plg <span style='color:#111;'> 248B </span>","children":null,"spread":false},{"title":"res","children":[{"title":"TestDlg.ico <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false},{"title":"TestDlg.rc2 <span style='color:#111;'> 399B </span>","children":null,"spread":false}],"spread":true},{"title":"TestDlg.aps <span style='color:#111;'> 20.36KB </span>","children":null,"spread":false},{"title":"TestDlg.dsw <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false},{"title":"TestDlg.clw <span style='color:#111;'> 1.56KB </span>","children":null,"spread":false},{"title":"TestDlg.dsp <span style='color:#111;'> 4.13KB </span>","children":null,"spread":false},{"title":"TestDlg.opt <span style='color:#111;'> 63.00KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 209B </span>","children":null,"spread":false},{"title":"resource.h <span style='color:#111;'> 685B </span>","children":null,"spread":false},{"title":"TestDlgDlg.cpp <span style='color:#111;'> 4.30KB </span>","children":null,"spread":false},{"title":"TestDlg.cpp <span style='color:#111;'> 2.03KB </span>","children":null,"spread":false},{"title":"TestDlg.h <span style='color:#111;'> 1.30KB </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 1.03KB </span>","children":null,"spread":false},{"title":"TestDlg.ncb <span style='color:#111;'> 81.00KB </span>","children":null,"spread":false},{"title":"TestDlgDlg.h <span style='color:#111;'> 1.35KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 3.51KB </span>","children":null,"spread":false}],"spread":false},{"title":"B","children":[{"title":"B.def <span style='color:#111;'> 22B </span>","children":null,"spread":false},{"title":"B.dsw <span style='color:#111;'> 525B </span>","children":null,"spread":false},{"title":"B.dsp <span style='color:#111;'> 4.22KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 288B </span>","children":null,"spread":false},{"title":"B.cpp <span style='color:#111;'> 354B </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 802B </span>","children":null,"spread":false},{"title":"B.ncb <span style='color:#111;'> 33.00KB </span>","children":null,"spread":false},{"title":"B.plg <span style='color:#111;'> 3.15KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 1.55KB </span>","children":null,"spread":false},{"title":"B.opt <span style='color:#111;'> 47.50KB </span>","children":null,"spread":false}],"spread":true},{"title":"Bin","children":null,"spread":false},{"title":"A","children":[{"title":"A.plg <span style='color:#111;'> 1.54KB </span>","children":null,"spread":false},{"title":"A.cpp <span style='color:#111;'> 304B </span>","children":null,"spread":false},{"title":"A.opt <span style='color:#111;'> 47.50KB </span>","children":null,"spread":false},{"title":"A.dsp <span style='color:#111;'> 4.22KB </span>","children":null,"spread":false},{"title":"A.ncb <span style='color:#111;'> 33.00KB </span>","children":null,"spread":false},{"title":"A.def <span style='color:#111;'> 7B </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 288B </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 802B </span>","children":null,"spread":false},{"title":"A.dsw <span style='color:#111;'> 525B </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 1.55KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

  • June_Hou :
    是window 编程代码.不是linux c,很有参考意义,不过第一个结论,在linux 中并不是一样:1.最终生成的可执行程序,全局变量在编译链接的时候已经确定好,如果静态a定义与动态库b全局变量重
    2018-07-05
  • 织梦科技 :
    简单的例子, 供懒人参考一下
    2016-10-05
  • feng9876 :
    最简单的例子了
    2015-09-07
  • clanbin_cpp :
    谢谢,学到了点东西
    2014-11-16
  • 风一样的逗比 :
    挺好的,帮助挺大的
    2014-11-10
  • 阿鼎 :
    最简单的例子了
    2014-01-20
  • lanyulianying :
    谢谢,很好用
    2013-11-15
  • 思睿3 :
    确实很有用处 ,受教了
    2013-07-05
  • I_Have_123456 :
    确实有帮助
    2013-03-21
  • SoftwareCEO :
    谢谢,很有帮助
    2013-03-18

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明