Re: size of enum when used with NSCoder decodeValueOfObjCType: ??? int?
Re: size of enum when used with NSCoder decodeValueOfObjCType: ??? int?
- Subject: Re: size of enum when used with NSCoder decodeValueOfObjCType: ??? int?
- From: tyler <email@hidden>
- Date: Tue, 24 Jul 2001 22:38:13 -0700
Hey There,
Clark's suggestion seems like it is a good one to avoid the issue
and for sure work correctly (unless your enum is larger than a char in
range). I was sort of looking for a solution that would always work.
Here's what one person wrote me directly:
A helpful chap name of Chris suggested the following via private email:
Use @encode(statusType) instead of @encode(int) for both the encode and
decode
If that works it seems much cleaner.
The only issue I can see with this solution is one of code evolution:
If values are added to the enum later on down the road and the size
needed to store the range of values crosses the threshold to promote the
size to the next size up, then the application will not read files saved
with the previous versions...
Of course this assumes that the compiler uses the smallest possible
native data structure to store the enum. What is the convention for
this in ObjC ?
Anyone else have any thoughts on the "correct" or "optimal" way to
handle this?
So is there a way to force the size of an enum? Or is it always the
same size?
Curious.
peace,
tyler
On Tuesday, July 24, 2001, at 04:37 PM, Clark S. Cox III wrote:
On Tuesday, July 24, 2001, at 06:51 , tyler wrote:
Hey All,
So anyone know what type to use with the NSCoder protocol for
enums...?
In CW there was an "enums always int" preference to force int size
for enums, though that caused real problems with the MSL if you were
not careful.
Here's where I'm wondering:
typedef enum statusType {
SOME_STATUS_NO = 0,
SOME_STATUS_YES,
SOME_STATUS_MAYBE
} statusType;
- (id)initWithCoder:(NSCoder *) aDecoder
{
[ aDecoder decodeValueOfObjCType: @encode(int) at:
&status ]; // int??
}
How about this:
- (id)initWithCoder:(NSCoder*)aDecoder
{
unsigned char temp;
[ aDecoder decodeValueOfObjCType: @encode(unsigned char) at: & temp ];
status = (statusType )temp;
}
--
Clark S. Cox, III
email@hidden
http://www.whereismyhead.com/clark/
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev