Find the answer to your Linux question:
Results 1 to 2 of 2
Some head scratching going on here: Code: gchar *data = "a-string-that-might-be-4-bytes-or-4000-Ive-tried-both..."; gchar *xpms[] = { data, //<-- why is this not constant? "terminal64.xpm", //<-- but this is. NULL }; I'm ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    340

    gcc - initializer element is not constant?


    Some head scratching going on here:
    Code:
    gchar *data = "a-string-that-might-be-4-bytes-or-4000-Ive-tried-both...";
    
    gchar *xpms[] = {
        data,                           //<-- why is this not constant?
        "terminal64.xpm",               //<-- but this is.
        NULL
    };
    I'm thinking it needs a shaman and a special dance with drums under the full moon on a clear night when Venus is overhead, some magic potions bubbling over a bonfire made from the bones of an ancient blue dragon while an elder reads verses from the codex of K&R...

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    340

    Red face

    Duh. I knew I had forgotten something. After reading the Esoteric Psalms of the Grand Wazoo I figured it out.

    The initializers _must_ be inside the function scope, eg:
    Code:
    gchar *data = "a huge string from a header file...";
    
    void create_xpms ( void ) {
    
        gchar *xpms[] = {
            data,                           //<-- now I'm constant!
            "terminal64.xpm",               //<-- me too.
            NULL
        };
    
        /* a bunch of code */
    
    }
    That's good, because the fires of the ancient blue dragon are burning low, the potions are gone, and the shaman wants to go to bed...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •