Re: Hex to NSString or NSData
Re: Hex to NSString or NSData
- Subject: Re: Hex to NSString or NSData
- From: Michael Ash <email@hidden>
- Date: Sun, 10 May 2009 07:45:59 -0400
On Sun, May 10, 2009 at 4:50 AM, Uli Kusterer
<email@hidden> wrote:
> On 10.05.2009, at 05:57, Mr. Gecko wrote:
>>
>> int char2hex(unichar c) {
>> switch (c) {
>> case '0' ... '9': return c - '0';
>> case 'a' ... 'f': return c - 'a' + 10;
>> case 'A' ... 'F': return c - 'A' + 10;
>> default: return -1;
>> }
>> }
>
>
> As long as you are aware that this is not standard C, but actually a GCC
> extension that implements a feature dearly missed from Pascal...
>
> Ranges in switches will not compile on any other compiler than GCC. And
> before you think that won't affect you, remember that Apple are working on
> the clang compiler front-end and the llvm backend, which might one day
> become a new compiler completely independent from GCC.
>
> Thank you though -- I wasn't even aware that GCC had this extension before
> I tried to compile this code and then started googling.
However, clang's goal is full compatibility with gcc, including all
the weird language extensions. No doubt they haven't achieved it, but
you should be *pretty* safe using stuff like this. Better to avoid it
if you can, of course, but it's probably going to work.
Also, "one day" is not quite true. Clang works right now. The main
trouble it has is C++ support, but if you're doing plain old C and
ObjC you can download it and start using it now.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden