I am going over a sample project from Apple called Mixer Host. In the callback function there are a few lines which use the "->" syntax to refer to mBuffers which is a struct. I thought this was C++ syntax but this file has a .m extension which I thought was C plus Objective-C extensions. Is this actually C++ syntax? Can I put C++ syntax into a .m file without renaming it as .mm with Xcode?
AudioUnitSampleType *outSamplesChannelLeft;
AudioUnitSampleType *outSamplesChannelRight;
outSamplesChannelLeft = (AudioUnitSampleType *) ioData->mBuffers[0].mData;
if (isStereo) outSamplesChannelRight = (AudioUnitSampleType *) ioData->mBuffers[1].mDat开发者_运维技巧a;
No, that's perfectly valid C. It's how you refer to data members via a pointer in both C and C++.
In C++ you can also refer to member functions that way, but there's no function call in sight.
I don't know Objective-C, but "->" has been in C since he K&R days. I'm certain it's valid Objective-C. It is not a C++ addition.
Assuming that AudioUnitSampleType
is a structure/class, it could be either C++ or Objective-C. Simply because pure C would require stating struct
before its name when you declare a variable (pointer). It could be anything otherwise. Usually, Objective-C++ files has .mm
extension unless you change Xcode to treat .m
files as Objective-C++, which is not likely. So this code turns out to be Objective-C.
精彩评论