Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang C Compiler 'class' keyword reserved?

Hi I am compiling ffmpeg using xcode, which I believe uses clang for compilation. In ffmpeg there is a struct with a member variable named 'class' I believe this is perfectly fine in C but clang is trying to parse it as a keyword. Any idea how to fix? Basically the following in a cpp file will cause the error:

extern C {
    typedef struct {
        int class;
    } SomeStruct;
}

It tries to interpret class as a keyword.

FYI the file that is throwing the error in ffmpeg is libavcodec/mpegvideo.h and I need to include this to have access to the MpegEncContext struct to pull out motion map info.

EDIT

The above code sample was just to demonstrate the error. But perhaps its fixable in another way. In my actual code I have it like this:

#ifdef __cplusplus
extern "C" {
#endif

    #include "libavcodec/mpegvideo.h"
    #include "libavformat/avformat.h"

#if __cplusplus
} //Extern C
#endif

How would I get that to include the two files as C files and not C++?

Thanks

like image 475
user1689196 Avatar asked Sep 21 '12 15:09

user1689196


1 Answers

It's completely fine in C. When you build that as C++, you encounter an error because class is a C++ keyword.

As far as fixing it, you would normally choose an identifier other than class. However, ffmpeg developers may not be so agreeable with that change. Therefore, you may need to either:

  • restrict the visibility of that header to C translations
  • or edit your own copy in order to use it in C++ translations

Fortunately, you are also using a C compiler which has good support of C99 features in this case. C Compilers which do not support C99 well are particularly troublesome with ffmpeg sources (because you would then compile the whole program as C++ for the C99 features, and the conflict count would be much higher).

(there are other dirty tricks you could do to try to work around the problem, but i will not mention them)

like image 91
justin Avatar answered Oct 03 '22 05:10

justin