Relative Content

Tag Archive for c++arraysstruct

brace elision on struct template doesn’t work like std::array

#include <array> template<class T, int N> struct X {T array[N];}; int main() { using std::array; array<int,3> a{1,2,3}; //works array<int,3> c{{1,2,3}}; //works array b{1,2,3}; //works array d{{1,2,3}}; //doesn’t work X<int,3> e{1,2,3}; //works X<int,3> f{{1,2,3}}; //works X g{1,2,3}; //doesn’t work X h{{1,2,3}}; //works } When I create a std::array variable with CTAD (no template arguments), brace elision […]

C++/Arduino store struct data in array

I’m writing a class for a Raspberry Pi Pico (using Arduino) that involves communicating via modbus. I am using structs to organise my data into ID data, status data, measurement data etc. I would like these structs to share the same memory as the modbus array to avoid a memcpy every time I change a variable or receive a message. I can do similar using arrays as follows: