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: NSData dataWithBytes problem on Intel




On Mar 21, 2007, at 2:27 PM, Sam Waters wrote:

The solution:

Here's what I was doing:

NSData * dTempData = [NSData dataWithBytes:[self Function] length:iLen];

iLen is a class variable that got updated in Function. On the PPC iLen would be
updated in time, but on the Intel it wouldn't be. Oddly enough that same line
of code works fine on my Windows XP port. (in C++ syntax of course)

If you look in the dictionary under "undefined behavior in the C language" yours is the example that is given. The usual way it is shown is:


foo(++i, ++i);

The order of evaluation of function parameters is undefined.

The reason for this is efficiency. If the language standard required any particular order of parameter evaluation then in some circumstances, on some hardware, that ordering would be less efficient than another order. The compiler is free to choose the most efficient order. It has always been this way.

Since the order of parameter evaluation is undefined the compiler can change this order for any reason. Typically it can change based on optimization settings. Since the Mac OS X ABI is different between PPC and Intel it may change between those different architectures. Obviously it may change between different compilers.

Writing code that depends on undefined behavior is writing buggy code.


-- Brian Stern email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: NSData dataWithBytes problem on Intel (From: Sam Waters <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.