草庐IT

test_sizeof

全部标签

c++ - 指针数组和sizeof混淆

为什么下面的代码输出4?char**pointer=newchar*[1];std::cout我有一个指针数组,但它的长度应该是1,不是吗? 最佳答案 pointer是一个指针。它是一个指针的大小,在您的系统上是4个字节。*pointer也是一个指针。sizeof(*pointer)也将是4。**pointer是一个字符。sizeof(**pointer)将为1。请注意,**pointer是一个字符,因为它被定义为char**。数组new`ednevers的大小进入这个。请注意,sizeof是编译器运算符。它在编译时呈现为常量。任何

c++ - 指针数组和sizeof混淆

为什么下面的代码输出4?char**pointer=newchar*[1];std::cout我有一个指针数组,但它的长度应该是1,不是吗? 最佳答案 pointer是一个指针。它是一个指针的大小,在您的系统上是4个字节。*pointer也是一个指针。sizeof(*pointer)也将是4。**pointer是一个字符。sizeof(**pointer)将为1。请注意,**pointer是一个字符,因为它被定义为char**。数组new`ednevers的大小进入这个。请注意,sizeof是编译器运算符。它在编译时呈现为常量。任何

c++ - ./配置错误: The test for linking against libxcb and support libraries failed

我正在尝试在DebianWheezy上构建Qt5。我运行配置脚本:./configure-developer-build-opensource-nomakeexamples-nomaketests但它失败并出现此错误:Runningconfigurationtests...Thetestforlinkingagainstlibxcbandsupportlibrariesfailed!Youmightneedtoinstalldependencypackages,orpass-qt-xcb.Seesrc/plugins/platforms/xcb/README.即使libxcb1-dev

c++ - ./配置错误: The test for linking against libxcb and support libraries failed

我正在尝试在DebianWheezy上构建Qt5。我运行配置脚本:./configure-developer-build-opensource-nomakeexamples-nomaketests但它失败并出现此错误:Runningconfigurationtests...Thetestforlinkingagainstlibxcbandsupportlibrariesfailed!Youmightneedtoinstalldependencypackages,orpass-qt-xcb.Seesrc/plugins/platforms/xcb/README.即使libxcb1-dev

c++ - 在 typedef 上使用 sizeof 而不是局部变量

就像这个例子一样(在C中):typedefinttype;intmain(){chartype;printf("sizeof(type)==%zu\n",sizeof(type));//Outputs1}输出总是局部变量type的大小。当C++不再需要在每次使用结构之前编写struct时,它仍然保留了struct{type}语法并引入了别名(class{type})以显式引用结构或类。示例(在C++中):structtype{intm;};intmain(){chartype;printf("sizeof(type)==%u\n",sizeof(type));//Outputs1pri

c++ - 在 typedef 上使用 sizeof 而不是局部变量

就像这个例子一样(在C中):typedefinttype;intmain(){chartype;printf("sizeof(type)==%zu\n",sizeof(type));//Outputs1}输出总是局部变量type的大小。当C++不再需要在每次使用结构之前编写struct时,它仍然保留了struct{type}语法并引入了别名(class{type})以显式引用结构或类。示例(在C++中):structtype{intm;};intmain(){chartype;printf("sizeof(type)==%u\n",sizeof(type));//Outputs1pri

c++ - 如果 T 是一个函数,不要对 T 使用 sizeof

我有近乎以下的结构来检测类型是否可以按值传递:templatestructshould_be_passed_by_value{staticconstexprboolvalue=std::is_scalar::value||std::is_array::value||std::is_reference::value||(sizeof(T)问题是:当我为类C函数指针或std::function实例化它时,编译器说:invalidapplicationof'sizeof'toafunctiontype(当然)。如何修改它以使value包含false? 最佳答案

c++ - 如果 T 是一个函数,不要对 T 使用 sizeof

我有近乎以下的结构来检测类型是否可以按值传递:templatestructshould_be_passed_by_value{staticconstexprboolvalue=std::is_scalar::value||std::is_array::value||std::is_reference::value||(sizeof(T)问题是:当我为类C函数指针或std::function实例化它时,编译器说:invalidapplicationof'sizeof'toafunctiontype(当然)。如何修改它以使value包含false? 最佳答案

c++ - 不评估应用了 sizeof 的表达式是否使得在 C++ 中取消引用 sizeof 内的空指针或无效指针是合法的?

首先,我见过thisquestionaboutC99并且接受的答案引用了C99标准草案中的operandisnotevaluate措辞。我不确定这个答案是否适用于C++03。还有thisquestionaboutC++有一个接受的答案,引用了类似的措辞,并且在某些情况下,会出现未评估的操作数。未计算的操作数不会被计算。措辞。我有这个代码:int*ptr=0;void*buffer=malloc(10*sizeof(*ptr));问题是-sizeof()内是否有空指针取消引用(以及UB)?C++035.3.3/1说sizeof运算符在其操作数的对象表示中产生字节数。操作数要么是一个未计算

c++ - 不评估应用了 sizeof 的表达式是否使得在 C++ 中取消引用 sizeof 内的空指针或无效指针是合法的?

首先,我见过thisquestionaboutC99并且接受的答案引用了C99标准草案中的operandisnotevaluate措辞。我不确定这个答案是否适用于C++03。还有thisquestionaboutC++有一个接受的答案,引用了类似的措辞,并且在某些情况下,会出现未评估的操作数。未计算的操作数不会被计算。措辞。我有这个代码:int*ptr=0;void*buffer=malloc(10*sizeof(*ptr));问题是-sizeof()内是否有空指针取消引用(以及UB)?C++035.3.3/1说sizeof运算符在其操作数的对象表示中产生字节数。操作数要么是一个未计算