B
Bill Pursell
I've found myself wanting to do this:
int *x = {1,2,3,4,5};
Obviously, I can't do that. I can certainly non-portably
hack it like int *x = (int *)"\x01\x00\x00\x00\x02\x00...",
but that's the worst idea since W's last one.
Or I can do:
int a[] = {1,2,3,4,5};
int *x=a;
but this is not ideal for the reasons given below.
Is there a way to accomplish the above initialization?
My motivation is the following:
struct args {
int *x;
...
};
#define DEFAULT_ARGS (struct args) {\
.x = DEFAULT_INT_ARRAY;\
...
}
If I can make the assignment happen, then modifying
the defaults is contained in the definition of the DEFAULT_ARGS
macro, but if I can't assign in this way, then DEFAULT_INT_ARRAY
needs to be defined outside of that definition. Granted, it
can be in the immediately preceding line, but it would
be really nice if I could keep it local.
Any thoughts?
int *x = {1,2,3,4,5};
Obviously, I can't do that. I can certainly non-portably
hack it like int *x = (int *)"\x01\x00\x00\x00\x02\x00...",
but that's the worst idea since W's last one.
Or I can do:
int a[] = {1,2,3,4,5};
int *x=a;
but this is not ideal for the reasons given below.
Is there a way to accomplish the above initialization?
My motivation is the following:
struct args {
int *x;
...
};
#define DEFAULT_ARGS (struct args) {\
.x = DEFAULT_INT_ARRAY;\
...
}
If I can make the assignment happen, then modifying
the defaults is contained in the definition of the DEFAULT_ARGS
macro, but if I can't assign in this way, then DEFAULT_INT_ARRAY
needs to be defined outside of that definition. Granted, it
can be in the immediately preceding line, but it would
be really nice if I could keep it local.
Any thoughts?