草庐IT

apc_define_constants

全部标签

c++ - 如何在模板代码中使用编译时常量条件避免 "conditional expression is constant"警告?

考虑代码:templateCByteArrayserialize(constT&value){if(std::is_pod::value)returnserializePodType(value);elseif(std::is_convertible::value)returnserialize(Variant(value));else{assert(0=="Unsupportedtype");returnCByteArray();}}显然,编译器给我这个警告是正确的if(std::is_pod::value)等等,但是我该如何规避呢?我找不到避免这种检查的方法,而且没有statici

c++ - 如何在模板代码中使用编译时常量条件避免 "conditional expression is constant"警告?

考虑代码:templateCByteArrayserialize(constT&value){if(std::is_pod::value)returnserializePodType(value);elseif(std::is_convertible::value)returnserialize(Variant(value));else{assert(0=="Unsupportedtype");returnCByteArray();}}显然,编译器给我这个警告是正确的if(std::is_pod::value)等等,但是我该如何规避呢?我找不到避免这种检查的方法,而且没有statici

c++ - 此错误消息是否正确 : non-type template argument is not a constant expression

以下程序可以使用GCC5.2编译,但不能使用clang3.6:constexprboolflag();templateconstexprbooltest(){returnb;}intmain(){}我用clang得到的错误信息是:main.cpp:3:20:error:non-typetemplateargumentisnotaconstantexpressiontemplate^~~~~~main.cpp:3:20:note:undefinedfunction'flag'cannotbeusedinaconstantexpressionmain.cpp:1:16:note:decla

c++ - 此错误消息是否正确 : non-type template argument is not a constant expression

以下程序可以使用GCC5.2编译,但不能使用clang3.6:constexprboolflag();templateconstexprbooltest(){returnb;}intmain(){}我用clang得到的错误信息是:main.cpp:3:20:error:non-typetemplateargumentisnotaconstantexpressiontemplate^~~~~~main.cpp:3:20:note:undefinedfunction'flag'cannotbeusedinaconstantexpressionmain.cpp:1:16:note:decla

C++1y/C++14 : Assignment to object outside its lifetime is not allowed in a constant expression?

根据当前草案,以下C++14/C++1y程序是否格式错误?#includetemplatestructliteral_array{Tdata[n];};templateconstexprliteral_arrayoperator+(literal_arraya,literal_arrayb){literal_arrayx;for(size_ti=0;ia={1,2,3};constexprliteral_arrayb={4,5};constexprautoc=a+b;}Clangtrunk(在撰写本文时)给出:error:constexprvariable'c'mustbeinitia

C++1y/C++14 : Assignment to object outside its lifetime is not allowed in a constant expression?

根据当前草案,以下C++14/C++1y程序是否格式错误?#includetemplatestructliteral_array{Tdata[n];};templateconstexprliteral_arrayoperator+(literal_arraya,literal_arrayb){literal_arrayx;for(size_ti=0;ia={1,2,3};constexprliteral_arrayb={4,5};constexprautoc=a+b;}Clangtrunk(在撰写本文时)给出:error:constexprvariable'c'mustbeinitia

c++ - Visual Studio C++ 编译器选项 : Why does/O2 define/Gs?

VisualStudioC++编译器选项/O2(最大化速度)相当于/Og/Oi/Ot/Oy/Ob2/Gs/GF/Gy为什么/Gs?它如何帮助最大限度地提高速度?(请注意,它是/Gs,而不是/GS。) 最佳答案 /Gs将在使用超过一页(通常为4kB)局部变量的函数中插入堆栈探测器。堆栈探测向操作系统发出信号,表明您将使用大量堆栈空间。如果这个探测命中保护页面,操作系统就知道它需要分配额外的RAM页面以使堆栈增长。这是一种优化,因为如果没有探测器,实际的内存访问会触发RAM分配,并且函数会停止直到分配RAM。探测作为函数prolog的一

c++ - Visual Studio C++ 编译器选项 : Why does/O2 define/Gs?

VisualStudioC++编译器选项/O2(最大化速度)相当于/Og/Oi/Ot/Oy/Ob2/Gs/GF/Gy为什么/Gs?它如何帮助最大限度地提高速度?(请注意,它是/Gs,而不是/GS。) 最佳答案 /Gs将在使用超过一页(通常为4kB)局部变量的函数中插入堆栈探测器。堆栈探测向操作系统发出信号,表明您将使用大量堆栈空间。如果这个探测命中保护页面,操作系统就知道它需要分配额外的RAM页面以使堆栈增长。这是一种优化,因为如果没有探测器,实际的内存访问会触发RAM分配,并且函数会停止直到分配RAM。探测作为函数prolog的一

c++ - 有没有一种正统的方法来避免编译器警告 C4309 - "truncation of constant value"与二进制文件输出?

我的程序执行将二进制数据写入文件的常见任务,符合某种非文本文件格式。由于我正在写入的数据尚未存在于现有block中,而是在运行时逐字节放在一起,因此我使用std::ostream::put()而不是write().我认为这是正常程序。该程序运行良好。它同时使用std::stringstream::put()和std::ofstream::put()以两位十六进制整数作为参数。但是我得到编译器警告C4309:"truncationofconstantvalue"(inVC++2010)每当参数到put()大于0x7f。显然编译器期待signedchar,常数超出范围。但我认为实际上并没有

c++ - 有没有一种正统的方法来避免编译器警告 C4309 - "truncation of constant value"与二进制文件输出?

我的程序执行将二进制数据写入文件的常见任务,符合某种非文本文件格式。由于我正在写入的数据尚未存在于现有block中,而是在运行时逐字节放在一起,因此我使用std::ostream::put()而不是write().我认为这是正常程序。该程序运行良好。它同时使用std::stringstream::put()和std::ofstream::put()以两位十六进制整数作为参数。但是我得到编译器警告C4309:"truncationofconstantvalue"(inVC++2010)每当参数到put()大于0x7f。显然编译器期待signedchar,常数超出范围。但我认为实际上并没有