默认构造的DDS主题类型可以发布吗?
Can a default constructed DDS topic type be published?
我正在使用带有 C++(C++11 绑定)的 OpenSplice DDS 6.4 OSS 版本。如果我尝试默认构造一个主题实例并发送它,也许修改它的某些字段,我会在作者的胆量中的某个地方得到访问冲突异常。这是一个错误,还是默认构造的对象无效的预期行为?
我用的IDL里面有很多union,我觉得可能是相关的。
IDL to C++ 语言映射说明了联合的默认初始化
The default union constructor performs no application-visible initialization of the union. It does not initialize the discriminator, nor does it initialize any union members to a state useful to an application. (The implementation of the default constructor can do whatever type of initialization it wants to, but such initialization is implementation-dependent. No compliant application can count on a union ever being properly initialized by the default constructor alone.)
因此构造一个默认的初始化主题实例并通过网络发送它是不安全的。
作为参考,IDL to C++11 语言映射如下
The default union constructor initializes the union. If there is a default case specified, the union is initialized to this default case. In case the union has an implicit default member it is initialized to that case. In all other cases it is initialized as empty. Assigning, copying, moving, and the destruction of default-constructed unions are safe.
我正在使用带有 C++(C++11 绑定)的 OpenSplice DDS 6.4 OSS 版本。如果我尝试默认构造一个主题实例并发送它,也许修改它的某些字段,我会在作者的胆量中的某个地方得到访问冲突异常。这是一个错误,还是默认构造的对象无效的预期行为?
我用的IDL里面有很多union,我觉得可能是相关的。
IDL to C++ 语言映射说明了联合的默认初始化
The default union constructor performs no application-visible initialization of the union. It does not initialize the discriminator, nor does it initialize any union members to a state useful to an application. (The implementation of the default constructor can do whatever type of initialization it wants to, but such initialization is implementation-dependent. No compliant application can count on a union ever being properly initialized by the default constructor alone.)
因此构造一个默认的初始化主题实例并通过网络发送它是不安全的。
作为参考,IDL to C++11 语言映射如下
The default union constructor initializes the union. If there is a default case specified, the union is initialized to this default case. In case the union has an implicit default member it is initialized to that case. In all other cases it is initialized as empty. Assigning, copying, moving, and the destruction of default-constructed unions are safe.