Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I output FourCharCode variable as text?



At 8:46 -0800 27-11-2003, Tom Becker wrote:
On 11/27/03 7:31 AM, Jim Hamilton wrote:
I can break that!

Print(0x30004142);

would be rendered as "0".

If it breaks, don't do that!

The FourCharCode type is for four character codes, as you can tell by the
name. This is not a user input type where we need to handle extreme and
nonsensical values. It is a type created by developers for developers. All
we need to do is establish a reasonable convention and follow it. A simple
hack allows using the type to convey numbers up to 538976287 (0x2020201F).
That is a lot of numbers. If that is not enough for your application, use a
different type, such as UInt32 or CFStringRef.

What in the world are you talking about? The permissible range of values is determined by whoever defines the specific type in use (for OSType, ResType, etc., that would be Apple), not by whatever buggy display code Tom Becker happens to come up with.

Speaking of which:

At 23:41 -0800 26-11-2003, Tom Becker wrote:
Good point, but in MacRoman only the control characters are unprintable, so
a very simple test will at least produce something where you can tell what
it is:

void Print(FourCharCode id)
{
if (id >= 0x20202020)
printf("%.4s", (char*)&id);
else
printf("0x%08x", id);
}

I've actually used code like this before in applications where IDs were a
mixture of alpha codes and numbers.

Using (id >= 0x20202020) for the purpose you stated above is such an incredible conceptual mistake that by merely looking at it I feel my sanity is in danger. I'm serious, I'm going to close this window right away before my mind breaks down.
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: How do I output FourCharCode variable as text? (From: Tom Becker <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.