Duplicate const error with C ++ - C code packaging

I have C code that is included and used from a C ++ application, the important parts are here:

C code

ifdef __cplusplus
extern "C" {
endif

...
typedef void* problem_type;

...
int problematic_fn_proto( const problem_type const arg );

ifdef __cplusplus
}
endif

Unfortunately, this does not compile due to an error duplicate 'const'. This is a problem typedef. If I just change the function prototype:

int problematic_fn_proto( const void* const arg );

More problems. Sorry, I can’t delete typedef. Is there a solution here? I can make other changes to part C, but typedef and use it as an argument to the function should remain.

+4
source share
1 answer

, , , problem_type , , double const (const ) , re . , typedef

-, typedef:

typedef void problem_type;
int problem_fn_proto( const problem_type* const arg);

const typedef:

typedef void const* cproblem_type;
typedef void* problem_type; // non-const variant not used here
int problem_fn_proto(cproblem_type const arg);

cproblem_type , cproblem_type const ( ).

- , . , :

typedef void const* cproblem_type;
int problem_fn_proto(cproblem_type arg);
+7

Source: https://habr.com/ru/post/1612179/


All Articles