草庐IT

check_sizeof_voidp

全部标签

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

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

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++ - 成员函数检查 : Implement compilation-time checkings with C++11 features

我读到C++11有足够的静态检查(编译时),以便实现C++11的大部分内容(已删除)。(我在最近关于已删除概念的问题的评论中读到过此内容...-该问题因不具有建设性而很快被关闭)。下面的C++03代码仅检查类中是否存在成员函数(我的模板类要在该类上工作)。这里有4个搜索的成员函数,我总是使用相同的模式:定义函数原型(prototype)的typedef如果类型名称TExtension没有定义这样的成员函数,或者如果它有不同的原型(prototype),则调用static_cast会中断编译代码如下:templateclass{...voidcheckTemplateConcept(){

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)

c++ - GCC -fstack-check 选项在 C 中引发了什么异常

根据gcc文档-fstack-checkGeneratecodetoverifythatyoudonotgobeyondtheboundaryofthestack.Notethatthisswitchdoesnotactuallycausecheckingtobedone;theoperatingsystemmustdothat.Theswitchcausesgenerationofcodetoensurethattheoperatingsystemseesthestackbeingextended.我的假设是这个额外的代码会产生异常让操作系统知道。使用C语言时,我需要知道额外代码生成