小编v.o*_*dou的帖子

使用以前版本的编译器是否可以防止代码注入?

我想知道今天的现代编译器,如MS cc,gcc,clang,icc,更新的版本是否使用相同编译器的当前版本构建?

因为当然存在这种风险:
http://scienceblogs.com/goodmath/2007/04/15/strange-loops-dennis-ritchie-a/
http://c2.com/cgi/wiki?TheKenThompsonHack

我确信参与上述编译器开发的每个人都知道这个问题,代码由自身的早期版本注入编译器并无形地传播.

现在真正的问题,实际上并不是后门之一,但更多关于代码生成的正确性不是吗?如果构建链中某处某些变态扭曲是由纯错误引入的,那么今天的编译器会生成错误的代码,即使编译器的源代码看起来不错,因为Ken Thompson的缺陷?

因此,如果他们是自己建造的,他们如何保护自己?

c c++ compiler-construction compilation

29
推荐指数
2
解决办法
1014
查看次数

是否存在上下文表达“ ab :: c”有意义?

在C ++中,请考虑语法规则:

member-access-expressionLHS member-access-operator RHS
(op is .

LHS= unqualified,id-expression例如引用实例变量。
RHS=合格id-expression(带有至少一个嵌套标识符)

例: a.b::c

如果那能通过语义检查,那会是什么情况?

以下实验:

struct B{};

struct A
{
    B b;
};

int main()
{
    A a;
    a.b::c;
}
Run Code Online (Sandbox Code Playgroud)

退货

'b' is not a class, namespace, or enumeration
a.b::c;
  ^
Run Code Online (Sandbox Code Playgroud)

演示

这倾向于向我暗示,在成员访问权的右侧不会存在任何有关限定ID的法律案例。

c++

16
推荐指数
3
解决办法
991
查看次数

无法在函数定义的类外声明符中完全限定类名

该程序导致不希望的贪婪解析的死胡同:

struct float4x4 {};
class C
{
    float4x4 M();
};

float4x4 ::C::M()
{
    return float4x4{};
}
Run Code Online (Sandbox Code Playgroud)

:8:1:错误:'float4x4'中没有名为'C'的成员; 您的意思仅仅是“ C”吗?
float4x4 :: C :: M()
^ ~~~~~~~~~~~~

可以使用尾随返回类型“固定”:

auto ::C::M() -> float4x4
{}
Run Code Online (Sandbox Code Playgroud)

现在一切都好。

因此,我认为在使用heading-return-type声明符语法时,我们不能完全限定类名吗?

c++ methods parsing fully-qualified-naming

12
推荐指数
1
解决办法
87
查看次数

哪个更好"目的地,来源"或"来源,目的地"?

我的问题是语言超越,我经常发现"复制"函数的原型按顺序定义参数:argument1:"destination"then argument2:"source".这是例如在C中的memcpy的情况.但它不是bash上的文件复制的情况!你说,例如:"$ cp file file2"其中file2是新文件.这对我来说更有意义,我们总是说"请在这里复制文本",而不是"复制这里的文字",这是尤达式.

所以真正的问题是:一个好的API应该使用什么形式(订单)?也许是另一个附属问题:每个人都期待什么形式,如果有的话?

api copy

11
推荐指数
1
解决办法
5144
查看次数

有没有办法可移植地检测使用宏包含标准头?

我希望boost::swap在我的环境中创建一个等效的标准头文件,或者不能包括在内.取决于项目许可和其他东西.
我想让部分代码受到保护检测器的保护:

我们考虑一个编译单元.
具体项目,上述潜力包括:

#include <algorithm> // (or <utility> for C++11 projects)
Run Code Online (Sandbox Code Playgroud)

稍后在我的交换实用程序头中包含的项目代码中:

namespace MyCompany
{
  template<class T1, class T2>
  void swap(T1& left, T2& right)
  {
     #ifdef _ALGORITHM_   // you get the idea.
       std::swap(left, right);
     #else
       // fallback impl
     #endif
  }
}
Run Code Online (Sandbox Code Playgroud)

我简化了,因为我们不是在讨论ADL技巧的细节,但它将被包括在内.
这里是我所谈论的参考,但这与这个问题无关:http:
//www.boost.org/doc/libs/1_57_0/boost/core/swap.hpp

所以这个问题是关于,如何检测标准头包含?在_ALGORITHM_后卫出现在Visual Studio中提供的头,但我无处阅读http://www.cplusplus.com/reference/algorithm/,它应该有,我可以检查任何宏.

(最后注意:这个问题有点偏向XY.我真正想要的是检测std::swap函数的存在,而不是标题.)

c++ utility

8
推荐指数
1
解决办法
118
查看次数

在(反)序列化树中使用自己的XmlSerializer将已知类型的列表传递给对象

我在microsoft .net 3.5(VS2008)上使用C#3.我有反序列化的问题.我在我想要序列化的类层次结构中使用DataContract和DataMember.

但是,我在一个容器中也有多态,所以我需要将已知类型的列表传递给序列化器.我的收藏是一个可在网上找到的可序列化词典:

[Serializable]
[XmlRoot("dictionary")]
public class SerializableSortedDictionary<TKey, TVal>
    : SortedDictionary<TKey, TVal>, IXmlSerializable
{
    #region Constants
    private const string DictionaryNodeName = "Dictionary";
    private const string ItemNodeName = "Item";
    private const string KeyNodeName = "Key";
    private const string ValueNodeName = "Value";
    #endregion

    #region Constructors
    public SerializableSortedDictionary()
    {
    }

    public SerializableSortedDictionary(IDictionary<TKey, TVal> dictionary)
    : base(dictionary)
    {
    }

    public SerializableSortedDictionary(IComparer<TKey> comparer)
    : base(comparer)
    {
    }

    public SerializableSortedDictionary(IDictionary<TKey, TVal> dictionary, IComparer<TKey> comparer)
    : base(dictionary, comparer)
    {
    }

    #endregion

    #region IXmlSerializable Members

    void IXmlSerializable.WriteXml(System.Xml.XmlWriter …
Run Code Online (Sandbox Code Playgroud)

c# constructor datacontract xmlserializer deserialization

5
推荐指数
1
解决办法
2294
查看次数

32位系统上的64 int64_t的字节序

我想知道,如果比本机字大,该类型有编译器支持的抽象,像int64_t一个32位系统上,在内存中的字节顺序上的任何规范?例如,在小端机器上,我们是否应该假设内存布局是一个完整的64位交换顺序?或者像PDP-11一样可以自由地成为中端?

cf http://en.wikipedia.org/wiki/Endianness#Middle-endian

因为在C99中的int64_t之前__int64(MS)或long long(gcc)不是标准的,所以在这种类型的字节顺序上假设有什么东西不是很遥远吗?

谢谢

c c++ endianness int64

5
推荐指数
1
解决办法
678
查看次数

函数中的自动参数类型

我想知道标准委员会是否考虑扩展 C++14auto关键字来推断函数模板参数类型,因为它现在存在于泛型 lambda 中。(正如在这个答案中可以很好地描述的那样

因为它适用于 lambda 函数,所以它也应该适用于任何函数。当然,使用经典语法将完全多余:

template< typename T >
void f(T param);
Run Code Online (Sandbox Code Playgroud)

但是能够写这个,以获得相同的结果:

void f(auto param);
Run Code Online (Sandbox Code Playgroud)

我认为可以减少阻塞的代码(更短更整洁),并在这个用例中实现很好的一致性:

auto v = func1();
f(v);
Run Code Online (Sandbox Code Playgroud)

如您所见,我们使用自动类型推导器来声明v,但随后我们必须使用硬类型参数化函数 f 或模板化函数 f。
结合auto我们应该使用auto,这将更加一致。

编辑:这个问题确实有效地提出了同样的问题,但不那么直接。并且还没有得到 user657267 给出的答案,我在其下复制和扩展。

c++ auto c++14 c++17

4
推荐指数
1
解决办法
1万
查看次数

警告:“matchIter”不是 GC 安全的,因为它访问“x”,这是使用 GC 内存的全局 [GcUnsafe2]

在 nim 中构建此代码时:

import jester, asyncdispatch    
let stuff = "thing"    
routes:
  get "/":
    resp stuff
runForever()
Run Code Online (Sandbox Code Playgroud)

结果是:

mytest.nim(3, 1) 模板/通用实例化来自此处 lib/core/macros.nim(369, 70) 模板/通用实例化来自此处 lib/pure/asyncmacro.nim(355, 31) 警告:“matchIter”是不是 GC 安全的,因为它访问的是使用 GC 内存的全局“东西”[GcUnsafe2]

我想它指的是变量stuff,并且我想很难诊断,因为小丑路由是某种 DSL。

如果该消息的意思就是它的意思,那么为什么它只是一个警告?还是误报?或者更重要的是,在路由中使用变量的概念根本不可能吗?

nim-lang jester

4
推荐指数
1
解决办法
1500
查看次数

std::is_same doesn't work through decltype of constexpr auto variable

I was trying to static_assert that some meta transformer algorithm worked, and it incredibly did not compare to same, even though the typeid().name() returned the exact same string.

A repetition of the type expression in the typedef could fix the is_same, but I can't understand how repeating the initializer expression in the typedef changes the type, over taking the decltype of an auto variable initialized with that same expression.

A more concrete explanation of what I was doing: …

c++ metaprogramming type-traits is-same

3
推荐指数
1
解决办法
144
查看次数