celephicus <> writes:
> This is what I want to do:
>
> int a, b;
> int *arr[] = { &a, &b, &arr[1], };
>
> Of course this won't work. Is there a (portable) way to achieve this?
I'm not sure what the "this" is. Your code tries to set arr[2] to a
pointer of an incompatible type (you can "fix" that with a cast but the
result will be odd). Also you don't say if this code is at file scope
or not and that makes a difference.
> The application is initialising an array that is a linked list, and I
> don't want to do it at runtime as I am on an embedded system with not
> much memory.
I think you've reduced your example beyond its usefulness! If you were
initialising an array so that it behaves like a linked list the elements
would be list nodes not pointers:
struct node { int v; struct node *next; };
struct node list[] = {
{ 2, list+1 },
{ 4, list+2 },
{ 8, list+3 },
{ 10, 0 },
};
I think you need to back up and show something closer to the code you
really have.
--
Ben.
|