On 1/16/2013 7:09 PM, walt wrote: > > > On 01/16/2013 10:22 AM, Zan Lynx wrote: >> I haven't looked at this code > > I've looked at little else for the last two days while trying to understand > it :) > I'm just an amateur programmer but I've done small projects with several other > programming languages, but c++ makes me feel completely stupid and I *hate* > that :( > >> Using "static" on a global variable in a .h file can result in >> independent unlinked copies in each .c or .cpp file that uses it. >> "static" at file scope means that variable exists only for that one >> file. > > You say "can result", not "will result". Does the actual result depend on the > definition of the c++ language itself, or at the discretion of the compiler > writers? Do you think the "average" c++ programmer knows the answer to this > question? I'm thinking probably not, but I'm happy to be corrected if I'm > wrong. I've set out to understand c++ at least four times over the years > and I've quit trying just as many times. I think this is my fifth try and > I haven't given up yet.....
As far as I know, it will always result in independent copies of the static variable. However there are some build scripts like what KDE uses that smush all the C++ files together into one large file, in order to achieve inter-module optimization. These days GCC has the LTO flag and the file smashing isn't needed but that is still fairly new. When all the files are smashed together I believe that you would get only one static variable defined, because the header files should have include guards which would include it only one time for all of the source files. _______________________________________________ Pan-users mailing list Pan-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/pan-users