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?
Since
NSAssert1is 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 theshortis converted toint, not tolongby default. That is why you should either insert an explicit cast, or use a different format specifier.