In C, you can wrap a value in a generic-selection that only supports one type:
#include <stdbool.h>
#include <stdio.h>
bool x = true;
int y = _Generic(1, bool:2);
int main(void) {
printf("%d\n", y);
}
This errors out (GCC 4.9), but will compile without complaint if you replace the 1
with true
or x
.
So for your example:
#include <stdbool.h>
void function( int value, bool flag ) { }
#define function(V, F) function(V, _Generic(F, bool:F))
int main() {
int a = 123;
bool flag = true;
function( flag, a ); // error: '_Generic' selector of type 'int' is not compatible with any association
}