C error: two or more data types in declaration specifier

created at 08-22-2021 views: 67

error when compiling libmemcached:

./config.h:632:15: error: two or more data types in declaration specifiers
 #define off_t long int
               ^
./config.h:632:20: error: two or more data types in declaration specifiers
 #define off_t long int
                    ^
./config.h:658:17: error: two or more data types in declaration specifiers
 #define ssize_t int

Since config.h is generated by automake tool, I don't know where to find the problem for a while.
First write a try.c file:

#define off_t long int
#define ssize_it int
int main() {
    return 1;
}

Can be compiled.
Many attempts have found that it is related to the order of #define. If #define off_t long int is before #define <stdxx.h>, an error will be reported, otherwise no error will be reported.
Through g++ -E -P try.c> xx, you can see:

#define long int __off_t
#define __off_t off_t

If #define off_t long int is before stdxx.h, long int will be used instead of off_t to become:

#define long int __off_t
#define __off_t long int

There is a loop, so an error will be reported
And if #define off_t long int is behind stdxx.h
It will not be executed because there is already #typedef __off_t off_t

In addition, during the debugging process, I found that #include "ah" can also be used #include <ah>. I used to think that local .h files can only be imported with "" instead of <>. Now I found that gcc -I. is used. -I and include directories can use <> to import local h files.

In addition, g++ can get pre-processed output in -E -P x.c, which is a .cc file. The extern "C" {...} in it requires pre-compiled output and it must be g++ compiled.

created at:08-22-2021
edited at: 08-22-2021: