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

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
Hi all,
May I ask what I thought would have been a simple issue. ( other questions relating to the same, ref a small difference, but usually sizeof is larger than strlen, ....accounted for by NULL)

Given this code:


Code:
NSString *testString = @"Some data value.";
const char  *cStringForHashValueClass = [testString UTF8String];
NSLog(@"\"sizeof\" \"%s\" = %i", cStringForHashValueClass, sizeof(cStringForHashValueClass) );
NSLog(@"\"strlen\" \"%s|' = %i", cStringForHashValueClass, strlen(cStringForHashValueClass));

output:

"sizeof" "Some data value." = 8
"strlen" "Some data value." = 16

strlen of 16 I understand. But why is storage of the same variable only 8 bytes?

Sorry if this is really obvious. :D
thank you.
 
And the pointer is 8 bytes because it's compiled and run for 64-bit.

If compiled and run for 32-bits, then sizeof the pointer would be 4, while strlen would still be 16.

thanks chown33 and Mac Player. I thought it might be that, but was not sure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.