Clang C Keyword 'class' compiler?

Hi, I am compiling ffmpeg with xcode, which I assume uses clang to compile. Ffmpeg has a structure with a member variable called "class". I find this to be excellent in C, but clang is trying to parse it as a keyword. Any idea how to fix it? Basically the following in the cpp file will throw an error:
extern C {
    typedef struct {
        int class;
    } SomeStruct;
}

He is trying to interpret the class as a keyword.

FYI, the file that throws an error in ffmpeg is libavcodec / mpegvideo.h, and I need to enable this in order to access the MpegEncContext structure in order to pull out the motion map information.

EDIT

The above code example was just to demonstrate the error. But perhaps this fix is ​​different. 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

, C, ++?

+5
3

C. ++, , class - ++.

, , class. ffmpeg . :

  • C-
  • , ++.

, C, C99 . C , C99, ffmpeg ( ++ C99, ).

( , , , )

+4

cpp

.cpp ++, C, class - ++.

+4

- , class -

#ifdef __cplusplus
extern "C" {
# define class videoClass
#endif

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

#if __cplusplus
# undef class
} //Extern C
#endif

This is a pretty dirty hack, but you don't have much choice for such poorly compatible code. The real solution would be for all the members structin these files to use names that we have some kind of prefix or the way it is done in network-level code. There, all members have some prefixes like ss_or sa_, and such problems are very unlikely.

+1
source

All Articles