Though I don't have all of the context, I suspect that this isn't really a 32/64 bit problem. What you probably want is something along the lines of:
id *argList = malloc(sizeof(id) * argumentsCount);
Depending on the situation, I sometimes like to allocate blocks of memory like this with the allocation already zero'd out:
id *argList = calloc(1UL, sizeof(id) * argumentsCount);
Both of these allocate a chunk of memory capable of holding argumentsCount
number of pointers to objects. You can access the individual pointers like so:
argList[0] = [[NSString alloc] initWithUTF8String:argv[0]];
argList[1] = [[NSString alloc] initWithUTF8String:argv[1]];
NSLog(@"Argument 0 is: %@", argList[0]);
When you declare argList
as a pointer to char
type, as you did in your example, indexing individual elements (ie, argList[0]
, argList[1]
), will access the individual bytes of the memory allocated for argList
, not the individual pointers as you're probably expecting. When you declare argList
as id
, as I did in the above, indexing individual elements steps through the memory allocated for argList
by sizeof(id)
bytes. The compiler will automatically compensate for the correct pointer size for the target architecture.
Assuming that the pointer returned by malloc()
is 0x1000
, here's a table of the addresses that would be calculated for 32 and 64bit mode for char *
and id *
declarations:
32-bit: char * id * 64-bit: char * id *
argList[0]: 0x1000 0x1000 0x1000 0x1000
argList[1]: 0x1001 0x1004 0x1001 0x1008
I have no idea why this ever worked for you in 32-bit mode.