Incompatible pointer types passing in _Generic macro

前端 未结 2 949
无人及你
无人及你 2020-11-28 14:38

The following code generates 2 warnings which are described in the question\'s title.

#include 

static void _print_f(float *f){printf(\"float         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 14:45

    This is not a bug in clang, but unfortunately what the C11 standard requires. All branches of a _Generic primary expression must be a valid expressions, and thus valid under all circumstances. The fact that only one of the branches will ever be evaluated, is not related to this.

    Your alternative version is what C11 foresees for situations as this: chose the function (and not the evaluated call) as a result of the type generic expression, and apply that function to the arguments.

提交回复
热议问题