In C an empty parameter list means that you don't specify how many arguments the function takes. To define a function with 0 parameters, you'd use (void)
as the parameter list. In C++ an empty parameter list means the function takes 0 parameters, so yes, C and C++ are not compatible in this instance.
I knew that the C++ should be compatible with C by design,but this case shows me incompatibility.This case happens by design?
While C++ is compatible to C in many instances, this is not the case all the time. Other examples are implicit casts from void*
(allowed in C, but not in C++) and keywords (it's perfectly valid to use something like class
as a variable name in C, but obviously not in C++ where it is a keyword). And yes, that's by design.