From: Wu Y. <ad...@ne...> - 2003-03-04 09:10:03
|
Your analogy to "extern" is precise. In fact, I think it will be much better if there is only dllimport and no dllexport. Dllexport is not really necessary. Theoretically Danny is correct (you see Microsoft gives warning on my test code), but GCC 3 is not: it should never generate such ugly code. In practice it is easier for programmers not necessary to use dllexport (best if dllimport could be removed too, like on Linux; but which seems not feasible for data at present when I want to link directly with the DLL without an import library), and MSVC, BCC, LCC, and GCC 2.95 can all compile the code correctly. Don't tell me that they are all doing the wrong things and only GCC 3 is doing correctly. Maybe I am mistaken, but I feel that GCC guys always want to defend GCC 3 against all accusations. Maybe you feel the same for me concerning GCC 2.95. My hearty words are that I don't feel much goodness about GCC 3. Probably GCC 3 will compile some cutting-edge templated C++ code, but I always want to have my code compilable on the mainstream C/C++ compilers, not for GCC 3 ONLY. -- Not to say that the new features are not good, but that I prefer other aspects like code compatibility (cf. standard conformance), stability, compilation speed, and code speed. IMHO GCC 3 is good at only the last point. Re your suggestion on code improvement. It is just a test case, my real code is far from that. For example, I might have two inline class member functions accessing the dllimport variable; do I need to declare them twice? What if I access them in 10 different places? -- In my opinion, a compiler should regard the dllimport attribute in such cases as dllexport, as the MSVC warning indicated what it was doing, or ignore it completely (I like the latter better for GCC, because of the automatic --export-all-symbols). -- If I change my code, I will choose to define DLLIMPORT to nothing (yes, the macro is used in real project code where it is defined as __declspec(dllimport) on Win32 and nothing otherwise) when compiling the DLL code to automatically enable the --export-all-symbols link feature. Best regards, Wu Yongwei --- Original Message from Earnie Boyd --- One could say the same about the extern declaration as well. However, the headers are often coded with extern and included in the initializing code without concern. However, IIRC, based on MS documentation, I believe Danny is correct. Below is a slight modification that gives you the results you expect. I don't know that it is a dependable one though. You may rather add filtering in the header file based on implementation of the variable. <newtest> static void test() { extern __declspec(dllimport) int SomeValue; SomeValue; // Any kind of access to it } int SomeValue = 0; </newtest> <result> 00000000 b .bss 00000000 d .data 00000000 t .text 00000000 t test() 00000000 D SomeValue </result> Earnie. |