2015年11月24日 星期二

sizeof trap

see more detail in jesrv blog

http://blog.linux.org.tw/~jserv/archives/001876.html


  1. A class with an empty sequence of members and base class objects is an empty class. Complete objects and member subobjects of an empty class type shall have nonzero size.

#include <stdio.h>
int main()                                                                                        
{
    printf("%d, %d\n", sizeof('J'), sizeof(char));
    return 0;
}


gcc output is
$ gcc -o sizeof sizeof.c
$ ./sizeof 4, 1
but g++ output is

$ g++ -o sizeof sizeof.c 
$ ./sizeof 1, 1
because 'j' default is integer in c, is char in c++


ex.  for (i = 0; i < sizeof(mcs_mask); i++)
is bug in below function, because the sizeof(mcs_mask) is pointer size, not equal to IEEE80211_HT_MCS_MASK_LEN

  static bool rate_control_cap_mask(struct ieee80211_sub_if_data *sdata,
                                   struct ieee80211_supported_band *sband,
                                   struct ieee80211_sta *sta, u32 *mask,
                                   u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])

沒有留言:

張貼留言