Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lumio

macrumors member
Original poster
May 20, 2008
54
0
Hi!
I want to define a special array. Right now it looks like this:
Code:
int translation[] = {
		1,
		2
};

But I would like to have it like this, so that the indexes are fixed:
Code:
int translation[] = {
		12 = 1,
		14 = 2
};

How to do that?

Greetings :)
 
Someone may need to correct me on this, but i don't think this is possible. It seems easiest to just do:
Code:
int translation[15];
translation[12] = 1;
translation[14] = 2;

Otherwise, you'd need to fill in the spaces with 0. Probably better to clear the memory anyway.

-Lee
 
Someone may need to correct me on this, but i don't think this is possible. It seems easiest to just do:
Code:
int translation[15];
translation[12] = 1;
translation[14] = 2;

Otherwise, you'd need to fill in the spaces with 0. Probably better to clear the memory anyway.

-Lee

that should work just fine.

Code:
int[] array = new int[]; array[12] = 1; array[14] = 2
 
Hi!
I want to define a special array. Right now it looks like this:
Code:
int translation[] = {
		1,
		2
};

Which programming language do you want the answer in? Your source looks valid in C, Objective-C, and Java, depending on context. It may also be valid in other languages.
 
Code:
	int translation [] = { [12] = 1, [14] = 2 };

Type "c99 standard draft" into Google the find the latest draft of the C99 Standard; Objective C is also based on that standard.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.