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.
  • 相关阅读:
    05-浮动/css
    04-选择器/css
    03-样式表/css
    02-html标签&表格&表单
    01-html基础&标签
    vue分页组件重置到首页问题
    VUE通过索引值获取数据不渲染的问题
    常见IE8兼容性问题及解决
    Ajax
    sea.js模块化工具
  • 原文地址:https://www.cnblogs.com/dayouluo/p/152878.html
Copyright © 2011-2022 走看看