c - Aix compilation error due to #define -


"1506-221 (s) initializer must valid constant expression."

in aix during compilation of header file facing issue.

in header file source

#define a(b) (a+b)

like that.

wherever macro "a"(ex:a(5)) used in source throws above error.

can me solve this?

edited:

in header file

#define a(b) (a+b) 

in source file

struct {    int a;    int b; } ain = {10, a(10)}; 

like .

you can't initialize structure non constant value, in case using 1 of structure fields suppose macro doesn't know since a isn't defined anything, try instead

#define init_struct(x, a, b) {x->a = a; x->b = x->a + b} while (0); 

and use this

struct {int a; int b;}; init_struct(&a, 10, 10); 

note: please don't this, instead initialize this

a.a = 10; a.b = a.a + 10; 

or if need initialize many of these write function instead.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -