2014-10-21 5 views
1

나는 매우 새로운 sparse입니다. 코드에서 노이즈를 제거하는 데 사용하고 있습니다. sparse이 경고를보고 왜왜 sparse가 sizeof (bool) 경고를보고합니까?

warning: expression using sizeof bool 

궁금 : 최근 어딘가에 코드 라인 : kzalloc(sizeof(bool) * nvhost_syncpt_nb_pts(sp), GFP_KERNEL); 나는이 sparse 경고가 발생했습니다. 인터넷 검색에서 sizeof (bool)가 컴파일러에 종속적이라는 사실을 발견했습니다. 이는 매우 분명합니다. 이 경고가 왜보고되어서는 안되는 sparse에 의해 제기되었는지 왜 저를 도와주십시오? 내가 틀렸다면 나를 바로 잡아주세요.

나는 gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)을 사용하고 있습니다.

#if !defined(__cplusplus) 
# if defined(_MSC_VER) || !defined(__STDC_VERSION__) || \ 
    (__STDC_VERSION__ < 199901L) 
// The Visual Studio C compiler and older versions of GCC do not support C99 
// and thus have no bool or stdbool.h. Make a simple definition of bool, 
// true, and false to make this deprecated interface compile in C. Force it 
// to 1 byte to have some chance of ABI compatibility between C and C++, in 
// case we don't remove this. 

typedef char bool; 
# define false 0 
# define true 1 
# else 
// In C99-compliant compilers, we can include stdbool.h to get a bool 
// definition. 
# include <stdbool.h> 
# endif 
#endif 

/** 
* @} 
* End addtogroup PP 
*/ 

#endif /* PPAPI_C_DEV_DEPRECATED_BOOL_H_ */ 

답변

4

당신이 evaluate.c에서 스파 스 자식 소스 트리를 살펴 경우 : parse.c에 다음

static struct symbol *evaluate_sizeof(struct expression *expr) 
{ 
    ... 
    if (size == 1 && is_bool_type(type)) { 
     if (Wsizeof_bool) 
      warning(expr->pos, "expression using sizeof bool"); 
     size = bits_in_char; 
    } 
    ... 
} 

개미 : 이제 부울과 같이 정의된다 가정 해 봅시다

keyword_table[] = { 
    ... 
    { "_Bool", NS_TYPEDEF, .type = &bool_ctype, .op = &spec_op }, 
    ... 
}; 

당신 sizeof(_Bool)은 모두 Wsizeof_bool에 의해 무시되지 않으면 경고로보고됩니다.

지금 코드 고려 :

kzalloc(sizeof(bool) * nvhost_syncpt_nb_pts(sp), GFP_KERNEL); 

을 잘 모르겠어요 무엇을 우리 bool 여기이지만, boolinclude/linux/types.h에서없는 경우 : 당신이 경고를 typedef _Bool bool; 당연.

On googling, I found that sizeof(bool) is compiler dependent which is very obvious.

을하지만 같은 추가 문서 this 도움이 될 수 있습니다 경고 뒤에 추론에 관해서는 사용자가 스스로를 알아 낸 것 같다.

경고가 사용자 코드와 관련이 없다고 생각하는 경우 -Wno-sizeof-bool으로 제거하십시오.