草庐IT

SIZEOF_ALIGNOF

全部标签

c++ - 在模板参数列表中使用 sizeof... 时为 "too few template arguments"(MSVC 2017)

以下最小示例不基于当前的MSVC2017(19.16)。它确实基于MSVC2015和2017(19.14)的旧版本、GCC、Clang和ICC。所以我怀疑这是一个编译器错误。有效吗?如果不是,为什么?#include#includetemplateautofoo(std::integer_sequence){returnstd::array{Is...};}std::arraybar(){returnfoo(std::make_integer_sequence());}有效的变体:投入unsigned(sizeof...(Is))在参数列表中作为默认参数替换unsigned(...)与

c++ - sizeof... 是否允许在模板参数中用于特化?

我正在尝试使用GCC4.7快照做一些类似的事情:templatestructfoo{staticconstintvalue=0;};//partialspecializationwherenisnumberofintsinxs:templatestructfoo{//error:templateargument‘sizeof(xs...)’//involvestemplateparameter(s)staticconstintvalue=1;};templatestructfoo{//Thiscompilesfine.sizeof(xs)issizeofint//eventhoughp

c++ - 英特尔编译器 - 错误 : identifier "alignof" is undefined

我正在尝试运行alignof运算符的示例。#includestructEmpty{};structFoo{intf2;floatf1;charc;};intmain(){std::cout当我用gcc(g++-std=c++11alignof.cpp)编译它时,我没有得到任何错误。但是当我用icc(icpc-std=c++11alignof.cpp)编译它时,我得到以下错误,我不知道为什么:cenas.cpp(13):error:typenameisnotallowedstd::cout我在同一台机器上运行代码,并使用module命令更改编译器。alignof运算符怎么可能未定义?

c++ - 为什么 sizeof...(T) 这么慢?在没有 sizeof...(T) 的情况下实现 C++14 make_index_sequence

我找到了C++14make_index_sequence“算法”的实现:templatestructindex_sequence{usingtype=index_sequence;};templateusinginvoke=typenameT::type;templatestructconcate;templatestructconcate,index_sequence>:index_sequence{};//\///----------//Ithinkhereisslowly.templatestructmake_index_sequence_help:concate>,invoke

c++ - 如何在没有 sizeof 的情况下最好地防止自定义断言中出现未使用的变量警告?

基于http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/中的建议一段时间以来,我一直在使用我自己的断言版本(称为emp_assert)。因此,当设置NDEBUG时,我的断言如下所示:#defineemp_assert(EXPR)((void)sizeof(EXPR))此定义确保EXPR中的任何变量在编译器中仍算作“已使用”,但不会影响运行时性能。不幸的是,我最近发现在断言中使用lambda会产生编译错误,因为lambda不能放入sizeof。我的选择似乎是:简单地删除sizeof;我的代码中很少有未使用变

c++ - 关于 C++ 中 sizeof 运算符的强大功能

我正在阅读现代C++设计。下面的描述中提到了sizeofoperator。以下段落从泛型编程的角度进行解释。Thereisasurprisingamountofpowerinsizeof:Youcanapplysizeoftoanyexpression,nomatterhowcomplex,andsizeofreturnsitssizewithoutactuallyevaluatingthatexpressionatruntime.Thismeansthatsizeofisawareofoverloading,templateinstantiation,conversionrules—

c++ - sizeof 对 gdb 中数组的引用

intmain(){typedefunsignedchara4[4];a4p1;a4&p2=p1;p2[1]=1;cout编译,启动gdb并在return处设置断点。如果您键入psizeof(p2),gdb将打印8而不是4,如果您启动该程序将打印4。如果您在gdb中编写psizeof(*p2),则输出为4(数组的大小)。我认为这是因为gdb将p2视为指针(引用在后台作为指针实现)。在GDB7.7linuxarch.、ubuntu13.10上使用编译器GCC4.8.2和Clang4.3进行测试这是正确的还是gdb中的错误? 最佳答案

c++ - 在初始化的未知大小数组中使用 sizeof() - C++

我是C++编程的新手,我正在尝试获取数组的大小。谁能解释我为什么会这样?我尝试在runnable.com中运行代码,结果显示相同。我确定这不是正确的方法。如果可能的话,你能建议任何简单的方法来获得这种数组的大小吗?#includeusingnamespacestd;intmain(){intset1[]={1,9,3,50,31,65};intset234[]={3,5,5};cout**编辑:感谢您的回复。飞走了:D 最佳答案 数组的大小等于其所有元素的大小之和。在您的示例中,您处理的是int类型的数组,那么系统中的sizeof(

c++ - sizeof pragma packed bitfield struct 数组

我将VisualStudio2013用于x64系统。我有以下结构:#pragmapack(1)structTimeStruct{intmilliseconds:10;BYTEseconds:6;BYTEminutes:6;BYTEhour:5;BYTEday:5;};#pragmapack()和一个数组:TimeStructstArray[10];当我使用sizeof(stArray);时,我得到80而不是40。我需要知道问题是编译器没有正确打包还是sizeof没有考虑位域的实际大小。谢谢 最佳答案 参见WhatisVC++doin

c++ - 在 C++ 标准中哪里说 sizeof(wchar_t) <= sizeof(long) 和 sizeof(bool) <= sizeof(long)?

先生。Stroustrup在他的新书(TCPL第4版)第149页写下了以下内容1我在标准中找不到任何支持上面最后一个不等式的内容。我可以对sizeof(bool)说同样的话.编辑:在3.9.1p5你会发现:Typewchar_tshallhavethesamesize,signedness,andalignmentrequirements(3.11)asoneoftheotherintegraltypes,calleditsunderlyingtype.支持不平等sizeof(wchar_t)但不是sizeof(wchar_t)但是我找不到任何可以证实的东西sizeof(bool)