2

I have a C header with this function:

OSStatus MyGetDataFromExtAudioRef(ExtAudioFileRef ext_file_ref, const AudioStreamBasicDescription* restrict output_format, ALsizei max_buffer_size, void** data_buffer, ALsizei* data_buffer_size, ALenum* al_format, ALsizei* sample_rate);

I can #include this header in an Objective-C file and compile fine.

If I change that same Objective-C file to a .mm suffix rather than .m and verify that it is now identified as Objective-C++ source, I get a compiler error that says Expected ')' on the line above. While not clear, it seems to be placing the source of the error on the word output_format parameter.

There is nothing in the above function that appears to be bad syntax, with regards to parenthesis, and I can't understand why this one change should make any difference.

Does anything jump out at anyone here?

johnbakers
  • 24,158
  • 24
  • 130
  • 258

1 Answers1

3

Simple, the restrict keyword isn't part of the C++ standard, so the C++ compiler (that is used to compile Objective-C++ code) doesn't recognize it.

JustSid
  • 25,168
  • 7
  • 79
  • 97
  • There is an `extern "C" {` at the top that should prevent it being compiled as C++ right? I just checked to verify that. But I had it commented out. I uncommented that out, and now the C++ compiler fails with the same parenthesis error for the `extern "C" {` -- is this phrase also not a C++ standard? – johnbakers Jan 22 '13 at 11:14
  • it would appear as though this issue is not unusual for others in similar positions http://stackoverflow.com/questions/7376003/linker-error-using-extern-c-in-objective-c-code I may just have to experiment with a variety of settings – johnbakers Jan 22 '13 at 11:19
  • @SebbyJohanns No, `extern "C"` will only change the way the name of the symbol is mangled to allow C++ code to link against C code (or client C code to link against parts of your C++ code). It will still be compiled using the C++ compiler. – JustSid Jan 22 '13 at 12:19
  • ok so the `restrict` is going to be handled by the C++ compiler no matter what, and there is no good way around it? – johnbakers Jan 22 '13 at 13:05
  • @SebbyJohanns `#ifdef __cplusplus\n#define restrict\n#endif` – Daniel Fischer Jan 22 '13 at 14:32