Question

This isn't giving me an error but several warnings I'd like to get rid of.

OSErr err = AudioUnitInitialize(toneUnit);
NSAssert1(err == noErr, @"Error initializing unit: %ld", err);

The warning I'm getting is: Format specifies type 'long' but the argument has type 'OSErr' (aka 'short'). Obviously I can change this by using long instead of OSErr but I was wondering why I'm getting the error. This is an upcast so I thought it shouldn't cause any problems.

Can anyone explain?

Was it helpful?

Solution

Since NSAssert1 is a variadic function implemented within the constraints of C, it cannot perform the cast internally: it is not possible to find the type of an argument passed in the vararg section of the function. Objective-C compiler will perform the default type promotions before making the call, but the short is converted to int, not to long by default. That is why you should either insert an explicit cast, or use a different format specifier.

OTHER TIPS

Use

NSAssert1(err == noErr, @"Error initializing unit: %hd", err);

or

NSAssert1(err == noErr, @"Error initializing unit: %ld", (long)err);

instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top