Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2017, 09:48:57 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 19 - Archiving
| | | |-+ Data ranges, archiving & 32/64 bit
Pages: [1] Go Down
Author Topic: Data ranges, archiving & 32/64 bit (Read 1506 times)
Posts: 35

on: May 28, 2010, 04:07:09 PM

I just need verify that the way i think here is correct, say that i have:
Code: (Objective-C)
long someValue;

And that i need the user of the program to input a value to this variable using scanf or by some other means if it's a GUI application, now because long could be treated as a 32bit or as a 64bit (depending on machine/os) i should treat it like its a 32bit storage to get it to work on both consistently.

I should check that the someValue is not larger than maximum range by: (Doing this because if it's archived on a machine that treats long as 64 bit we loose data when using the encodeInt32:forKey: method, also if its a machine that treats long as 32 bit we can't store larger values than INT32_MAX)
Code: (Objective-C)
if (someValue > INT32_MAX) NSLog(@"To large value inputted!");

if i had someValue unsigned, INT32_MAX would be replaced with UINT32_MAX.

And lastly if i wanted to archive this value, i would use the encodeInt32:forKey: method and unarchive it with decodeInt32ForKey:.

Using all this i would have consistent behavior on both 32 and 64 bit machines/OS's and the file could be archived on one and unarchived on other without loss of data. I could also declare someValue to be int32_t instead to save some memory in the program since the value is stored as 64bit but only half is used on those machines that tread long as a 64 bit.
Last Edit: May 28, 2010, 04:10:13 PM by sinth Logged
Pages: [1] Go Up
Jump to:

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.