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.
  • 相关阅读:
    组合模式
    迭代器模式
    命令模式
    装饰者模式
    观察者模式
    策略模式
    适配器模式和外观模式
    Servlet
    Java 递归
    Java 反射
  • 原文地址:https://www.cnblogs.com/dayouluo/p/152878.html
Copyright © 2011-2022 走看看