Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. static global object initialization order

static global object initialization order

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studioquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Scott H Settlemier
    wrote on last edited by
    #1

    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)

    S T 2 Replies Last reply
    0
    • S Scott H Settlemier

      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)

      S Offline
      S Offline
      Stefan Pedersen
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Scott H Settlemier

        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)

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups