• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UInt32 and ==
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UInt32 and ==


  • Subject: Re: UInt32 and ==
  • From: Andy Lee <email@hidden>
  • Date: Tue, 9 Apr 2002 10:06:57 -0400

At 10:46 PM +0900 4/9/02, Jaeho Chang wrote:
This does not return right results:

- (Boolean) isReadable
{
return (auParamInfo.flags & kAudioUnitParameterFlag_IsReadable);
}

but this does:

- (Boolean) isReadable
{
return (((UInt32) auParamInfo.flags & kAudioUnitParameterFlag_IsReadable) == ((UInt32) kAudioUnitParameterFlag_IsReadable));
}

By "Boolean" do you mean "BOOL"? I'll assume so.

BOOL is a typedef for char, which is only 8 bits. Your first version of -isReadable performs a bitwise operation on two 32-bit numbers but casts the result to an 8-bit value in order to return a BOOL. Since the last 8 bits of kAudioUnitParameterFlag_IsReadable are all 0, you will always get a 0, which is the same as the boolean value "NO".

Your second version of -isReadable performs the same 32-bit operation but compares the result to another 32-bit number via ==, which is a boolean (not bitwise) operator. The comparison will therefore yield the result you intended. So the key is to recognize the difference between bitwise and boolean operators and values. This is a C thing, not specific to Objective-C.

--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >UInt32 and == (From: Jaeho Chang <email@hidden>)

  • Prev by Date: Re: why Obj-C
  • Next by Date: ObjC and C++
  • Previous by thread: Re: UInt32 and ==
  • Next by thread: Re: UInt32 and ==
  • Index(es):
    • Date
    • Thread