Re: Installing property in interface



On Wed, Jan 31, 2007 at 11:23:17PM +0100, Tomasz Jankowski wrote:

static void
maman_ibaz_base_init (gpointer g_iface)
{
  static gboolean initialized = FALSE;

  if (!initialized) {
    /* create interface signals here. */
    initialized = TRUE;
  }
}

I'm quite young programmer (it's my hobby only), but I'm almost sure, that
all variables declared inside function are destroyed when function execution
if finished. Does 'static' keyword changes this behavior?!

Yes, static is probably the most confusing C keyword.  For
variables inside functions (and other blocks) it changes the
storage type:

  static void
  maman_ibaz_base_init (gpointer g_iface)
  {
    static gboolean initialized = FALSE;

    if (!initialized) {
      /* create interface signals here. */
      initialized = TRUE;
    }
  }

works the same as

  static gboolean initialized = FALSE;

  static void
  maman_ibaz_base_init (gpointer g_iface)
  {
    if (!initialized) {
      /* create interface signals here. */
      initialized = TRUE;
    }
  }

except that the name `initialized' is visible only in the
function maman_ibaz_base_init() in the first case.

Yeti


--
Whatever.



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