2

We use C++ static initialization order to control the construction of several objects in a C++ library. GCC offers init_priority, and Microsoft offers init_seg().

I'm looking for similar with IBM's XL C/C++ compiler, but my search results are not revealing useful hits. The compiler runs on both Linux and AIX. Obviously Linux offers the feature, but I am not sure about AIX runtime support.

My first question is, does the AIX platform support initialization priorities?

My second question is, does IBM's XL C/C++ offer a way to control it via the source code?

jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    Sounds like something that you should be able to find an answer to by digging through the xlc documentation. Have you tried searching that? Or maybe contact IBM support with your question.. – Jesper Juhl Nov 08 '17 at 18:36
  • @JesperJuhl - *"Have you tried searching tho [xlc docs]"* - Yes, I've been through both the AIX and Linux manuals, but I have not located it. I'm wondering if it goes by a different name, or if I assumed it was available when its not. The Linux xlC compiler seems seems like it should have it. – jww Nov 08 '17 at 18:39
  • Can you move the initializations to one file and put them in the order that you want? (using appropriate namespace statements, etc.) – stark Nov 08 '17 at 19:49

1 Answers1

1

IBM XL C/C++ for Linux V13.1.1 and up does offer a way to control initialization priorities, please see the Knowledge Center for more details about how to control it via the init_priority variable attribute, similar to GCC, which assigns static initialization priorities at the object level.

IBM XL C/C++ for AIX does not support init_priority but it does offer a way to control the order of initialization of global variables between .o files within the same link unit with -qpriority and #pragma priority. Details about those options can be found on Knowledge Center. In addition, -qmkshrobj=priority (Knowledge Center) controls the order of initialization of shared objects (and a.out) at program start up (XL AIX uses this method, whereas XL Linux uses dependency to determine shared object initialization order). The order within a translation unit has to be in declarative order otherwise you can get initialization referencing a variable that hasn't been initialized yet.

Nicole Trudeau
  • 678
  • 3
  • 8