Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C error: initializer element is not constant

Name: Anonymous 2009-02-04 15:43

I have some code that looks like this.


typedef struct {
   void *ptr;
} Foo;

static const size_t a = 1024;
static const size_t b = 1024;
static const size_t c = 1024;
static const size_t d = a * b + c * sizeof(Foo);


On the line declaring and initializing "d", I get the error "error: initializer element is not constant". Now, maybe I'm missing something, but aren't all of the operands there constant, therefore known at compile-time, therefore usable when initializing a constant?

Name: Anonymous 2009-02-04 17:28

>>4
GCC.

This has been discussed on http://www.reddit.com/r/programming/comments/7uwr6/c_error_initializer_element_is_not_constant/

I don't agree with it, but there's no point in fighting with the compiler. At least I've found a workaround.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List