c++ - 如何在编译时获得 'fill up' 大小的余数?

标签 c++

假设我有以下内容

struct MyType { long a, b, c; char buffer[remainder] }
我想做类似的事情
char buffer[4096 - offsetof(MyType, buffer)]
但是好像是违法的

最佳答案

你可以做:

struct ABC {long a,b,c; }
struct MyType : ABC {char buffer[4096-sizeof(ABC)];};
static_assert(sizeof(MyType)==4096,"!");

关于c++ - 如何在编译时获得 'fill up' 大小的余数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64094754/

相关文章:

c++ - Fortran 77 代码到 C++ 的转换

c++ - 设置一个 for 循环循环直到检测到空字节

c++ - 将 5 个 vector 合并到矩阵 C++

c++ - 将 C++ 连接到 Matlab 进行绘图

C++ undefined reference to function 错误仅在 g++ 编译器中

c++ - 我收到 'identifier not found' 错误

c++ - Qt:强制QWebView点击一个网络元素,即使是在窗口上不可见的元素

C++ long 过早溢出

c++ - 加载字体时 Allegro 5 崩溃

时间:2018-01-08 标签:c++mfc: update HWND through a control box