This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

`initializer element is not constant' issue


Aiee :)

   Hello!

   I'd like to initialize global variables outside of
   functions (as usual) in a slightly different manner;
   let's consider the attached file, please.

   Everything should be ok, but I get 

   `initializer element is not constant' error from the compiler.

   Is there a way to work around this, please? [1]

bye bye && thanks!

                     -- gg sullivan

[1]: I cannot/don't want to put these declaration inside some
functions.

-- 
Lorenzo Cavallaro	`Gigi Sullivan' <sullivan@sikurezza.org>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)

#include <stdio.h>
#include <sys/types.h>

void *func(char *, int, int);

#define DECLARE(name, type) \
caddr_t name = func(#name, strlen(#name), type);

void *
func(char *s, int len, int type)
{
   return s;
}

DECLARE(foo, 0x1);
DECLARE(bar, 0x2);
DECLARE(foobar, 0x3);
DECLARE(fubar, 0x4);

int
main(void)
{
        
   printf("%s\n", foo);
   printf("%s\n", bar);
   printf("%s\n", foobar);
   printf("%s\n", fubar);

   exit(0);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]