static global object initialization order
-
I have some number of static global objects, of which there is one that I want to be constructed first. Within a translation unit, it is simply the order in which the objects appear that determines their order of construction. But across translation units, it seems arbitrary. Is there a practical way to get the linker to accept a desired order of initialization in this case? (I use Visual Studio 6)
-
I have some number of static global objects, of which there is one that I want to be constructed first. Within a translation unit, it is simply the order in which the objects appear that determines their order of construction. But across translation units, it seems arbitrary. Is there a practical way to get the linker to accept a desired order of initialization in this case? (I use Visual Studio 6)
As far as I remember the C++ specs say that order of initialization of static objects is arbitrary. Easiest solution is to create ONE static object that acts as a "factory" for the others (which gives you control of the order). "was wir auch tun, wohin wir gehen die illuminaten sind im system sie kontrollieren überall und 23 ist ihre zahl!" 23, welle: erdball
-
I have some number of static global objects, of which there is one that I want to be constructed first. Within a translation unit, it is simply the order in which the objects appear that determines their order of construction. But across translation units, it seems arbitrary. Is there a practical way to get the linker to accept a desired order of initialization in this case? (I use Visual Studio 6)
By using the MS #pragma init_seg (which of course means is totally non-portable), you can control initialization order or even control when your variables are initialized and destroyed. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/pragm_14.asp[^] I would exhaust ALL other options before doing this. Tim Smith I'm going to patent thought. I have yet to see any prior art.