草庐IT

Constant

全部标签

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,常数超出范围。但我认为实际上并没有

c++ - 将局部变量的地址作为 C++11 中的常量表达式吗?

以下C++11程序:intx=42;voidf(){inty=43;static_assert(&x因为它提示不能用gcc4.7编译:error:‘&y’isnotaconstantexpression这符合我的直觉。y的地址每次调用f时可能会发生变化,所以翻译时当然不能计算。但是5.19[expr.const]中的所有要点似乎都没有阻止它成为一个常量表达式。我看到的仅有的两个竞争者是:anlvalue-to-rvalueconversion...但除非我弄错了(?),否则程序中没有左值到右值的转换。和anid-expressionthatreferstoavariable[snip]

c++ - 将局部变量的地址作为 C++11 中的常量表达式吗?

以下C++11程序:intx=42;voidf(){inty=43;static_assert(&x因为它提示不能用gcc4.7编译:error:‘&y’isnotaconstantexpression这符合我的直觉。y的地址每次调用f时可能会发生变化,所以翻译时当然不能计算。但是5.19[expr.const]中的所有要点似乎都没有阻止它成为一个常量表达式。我看到的仅有的两个竞争者是:anlvalue-to-rvalueconversion...但除非我弄错了(?),否则程序中没有左值到右值的转换。和anid-expressionthatreferstoavariable[snip]

c++ - 为什么我们需要两个定义: integral constant expression and converted constant expression?

C++14中的§5.19/3定义了一个整型常量表达式和一个转换后的常量表达式:Anintegralconstantexpressionisanexpressionofintegralorunscopedenumerationtype,implicitlyconvertedtoaprvalue,wheretheconvertedexpressionisacoreconstantexpression.[Note:Suchexpressionsmaybeusedasarraybounds(8.3.4,5.3.4),asbit-fieldlengths(9.6),asenumeratorini

c++ - 为什么我们需要两个定义: integral constant expression and converted constant expression?

C++14中的§5.19/3定义了一个整型常量表达式和一个转换后的常量表达式:Anintegralconstantexpressionisanexpressionofintegralorunscopedenumerationtype,implicitlyconvertedtoaprvalue,wheretheconvertedexpressionisacoreconstantexpression.[Note:Suchexpressionsmaybeusedasarraybounds(8.3.4,5.3.4),asbit-fieldlengths(9.6),asenumeratorini

C++ 警告 : deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

我正在使用gnuplot在C++中绘制图形。该图正在按预期绘制,但在编译期间出现警告。警告是什么意思?warning:deprecatedconversionfromstringconstantto‘char*’[-Wwrite-strings]这是我正在使用的功能:voidplotgraph(doublexvals[],doubleyvals[],intNUM_POINTS){char*commandsForGnuplot[]={"settitle\"ProbabilityGraph\"","plot'data.temp'withlines"};FILE*temp=fopen("da

C++ 警告 : deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

我正在使用gnuplot在C++中绘制图形。该图正在按预期绘制,但在编译期间出现警告。警告是什么意思?warning:deprecatedconversionfromstringconstantto‘char*’[-Wwrite-strings]这是我正在使用的功能:voidplotgraph(doublexvals[],doubleyvals[],intNUM_POINTS){char*commandsForGnuplot[]={"settitle\"ProbabilityGraph\"","plot'data.temp'withlines"};FILE*temp=fopen("da

python - Python 中的常量 : at the root of the module or in a namespace inside the module?

我正在构建一个包含大约一百个常量的Python模块。当人们导入我的模块时,我想避免命名问题,所以我想知道最好的方法是什么。MY_CONSTANT=1MY_SECOND_CONSTANT=2...MY2_CONSTANT="a"MY2_SECOND_CONSTANT="b"...或者classMy:CONSTANT=1SECOND_CONSTANT=2...classMy2CONSTANT="a"SECOND_CONSTANT="b"...或者你的其他建议?来自Java,我当然更喜欢第二种方式,但有些人可能会觉得它有点矫枉过正...... 最佳答案

python - Python 中的常量 : at the root of the module or in a namespace inside the module?

我正在构建一个包含大约一百个常量的Python模块。当人们导入我的模块时,我想避免命名问题,所以我想知道最好的方法是什么。MY_CONSTANT=1MY_SECOND_CONSTANT=2...MY2_CONSTANT="a"MY2_SECOND_CONSTANT="b"...或者classMy:CONSTANT=1SECOND_CONSTANT=2...classMy2CONSTANT="a"SECOND_CONSTANT="b"...或者你的其他建议?来自Java,我当然更喜欢第二种方式,但有些人可能会觉得它有点矫枉过正...... 最佳答案