Initializing struct (in C++)
-
I hope this is not going to be another one of "read the book" discussion. ( And if you already do not like my remark, do not read the rest of this post) This is very simple , but as always I am not sure about using correct terminology. The attached code , struct variable , is taken from C code tutorial. gcc++ compiler generates this error
sorry, unimplemented: non-trivial designated initializers not supported
Mrs Google say it is because gcc++ does not like C style "reference" "." It also say not to use "=" , but use ":" . OK, I generally can follow instructions , BUT If I do not use "." my IDE won't supply all available "options" anymore. No big deal, in this case, however I like to know if I can change some options in gcc++ or if this a IDE "issue".
/\* this is C construct struct spi\_ioc\_transfer tr = { .tx\_buf = (unsigned long)tx, .rx\_buf = (unsigned long)rx, .len = ARRAY\_SIZE(tx),
// .delay_usecs = delay,
.speed_hz = 0,
.bits_per_word = 0,
};generates error sorry, unimplemented: non-trivial designated initializers not supported
*/
struct spi_ioc_transfer tr = {
tx_buf:(unsigned long)tx,this works fine no error
//tx\_buf //.tx\_buf = (unsigned long)tx, //.rx\_buf = (unsigned long)rx, //.len = ARRAY\_SIZE(tx),
// .delay_usecs = delay,
// .speed_hz = 0,
// .bits_per_word = 0,
}; -
I hope this is not going to be another one of "read the book" discussion. ( And if you already do not like my remark, do not read the rest of this post) This is very simple , but as always I am not sure about using correct terminology. The attached code , struct variable , is taken from C code tutorial. gcc++ compiler generates this error
sorry, unimplemented: non-trivial designated initializers not supported
Mrs Google say it is because gcc++ does not like C style "reference" "." It also say not to use "=" , but use ":" . OK, I generally can follow instructions , BUT If I do not use "." my IDE won't supply all available "options" anymore. No big deal, in this case, however I like to know if I can change some options in gcc++ or if this a IDE "issue".
/\* this is C construct struct spi\_ioc\_transfer tr = { .tx\_buf = (unsigned long)tx, .rx\_buf = (unsigned long)rx, .len = ARRAY\_SIZE(tx),
// .delay_usecs = delay,
.speed_hz = 0,
.bits_per_word = 0,
};generates error sorry, unimplemented: non-trivial designated initializers not supported
*/
struct spi_ioc_transfer tr = {
tx_buf:(unsigned long)tx,this works fine no error
//tx\_buf //.tx\_buf = (unsigned long)tx, //.rx\_buf = (unsigned long)rx, //.len = ARRAY\_SIZE(tx),
// .delay_usecs = delay,
// .speed_hz = 0,
// .bits_per_word = 0,
};You have either set the C++ standard flags low or the default on your compiler is not c11++ or greater I have no issue with GCC or VS2017 taking structs like that. try the flag -std=c++11 or I would probably try and see if it is available -std=c++20 BTW if it is actually a C file you need different flag .. I know you were playing with C files before -std=c11 Now that I think about that I am guessing that is the issue you are compiling C files with G++ .. don't :-) Setup your make file to send C files to the c compiler gcc, you can make a rule based on the extension .c vs .cpp .c files => gcc .cpp files => g++ Visual Studio actually does exactly that it uses the filename extension to decide on c vs c++ compiling, which is why it works on it.
In vino veritas