zoukankan      html  css  js  c++  java
  • sizeof(enum_type)

    面试时候碰到。还有就是如何防止头文件重复定义,用
    #ifndef
    #def
    #enddef
    野指针,free后再置为NULL。

    sizeof(enum_type)
    C++标准p692:
    In C++,the type of an enumerator is its enumeration. In C,tye type of an enumerator is int.
       enum e{A};
       sizeof(A)==sizeof(int)   //in C
       sizeof(A)==sizeof(e)    //In C++
       /*and sizeof(int) is not nessary equal to sizeof(e) */

      那么怎么计算enumerator的sizeof?
    the c++ programming language 3rd edition 4.8
    The range of an enumeration holds all the enumeration’s enumerator values rounded up to the nearest larger binary power minus 1. The range goes down to 0 if the smallest enumerator is nonnegative and to the nearest lesser negative binary power if the smallest enumerator is negative. This defines the smallest bitfield capable of holding the enumerator values. For example:
       enum e1 { dark, light}; / / range 0:1
       enum e2 { a = 3, b = 9}; / / range 0:15
       enum e3 {min= 10, max = 1000000 }; / / range 1048576:1048575


    The sizeof an enumeration is the sizeof some integral type that can hold its range and not larger than sizeof(int), unless an enumerator cannot be represented as an int or as an unsigned int. For example, sizeof(e1) could be 1 or maybe 4 but not 8 on a machine where sizeof(int)==4.
  • 相关阅读:
    (1) C语言 基础1
    (5)数据契约
    hdu3592(差分约束) (线性)
    POJ3169 差分约束 线性
    BZOJ 3754 Tree之最小方差树 MST
    CodeForces788B 欧拉路
    【bzoj2152】聪聪可可 点分治
    POJ 1741 Tree【Tree,点分治】
    POJ3107 树的重心
    poj1655(dfs,树形dp,树的重心)(点分治基础)
  • 原文地址:https://www.cnblogs.com/dayouluo/p/152878.html
Copyright © 2011-2022 走看看