C int ( 4 - ), ++ bool ( 1).
.
Here's a C11 program that demonstrates that using _Generic(typical output int 4):
#include <stdio.h>
void what_int(){
printf("int %lu",sizeof(int));
}
void what_other(){
printf("other ?");
}
#define what(x) _Generic((x), \
int : what_int(),\
default: what_other()\
)
int main(void) {
what(1==1);
return 0;
}
Here's a C ++ program that demonstrates that using the specializaton pattern (typical output bool 1):
#include <iostream>
template<typename T>
void what(T x){
std::cout<<"other "<<sizeof(T);
}
template<>
void what(bool x){
std::cout<<"bool "<<sizeof(bool);
}
int main(){
what(1==1);
return 0;
}
I cannot readily think of any code that is both C and C ++ that would have a different result. Take it as a challenge.
source
share