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])

留言

這個網誌中的熱門文章

我們能利用machine learning去幫助compiler的optimization演算法變強嗎?

The Speed Game: Automated Trading Systems in C++

被討厭的勇氣 自我啟發之父阿德勒的教導