Re: global const variable not getting assigned properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Chad,

> Do you know why they are not getting initialized?

I presume because the .SO's global initializer is not being called.

> If I call dlopen instead will that help solve this problem?

Maybe.

> Is there something I can set to get those initialized before I use them?

Yes.

Instead of writing:
const int uno = 1;
const int dos = 2;
const int tres = 3;

Write this:

int GetUno()
{
  static int uno = 1;
  return uno;
}
int GetDos()
{
  static int dos = 1;
  return dos;
}
int GetTres()
{
  static int tres = 3;
  return tres;
}

Then use the accessor functions instead of globals.

In C/C++, there is no guarantee as to the order of construction betwixt
translation units.  This technique will guarantee order of construction
(provided you do not have a circular dependency).

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux