CONFIG_T cfg = { .str1 = { 0x01, 0x02 }, .str2 = { 0x03, 0x04 }, .str3 = { 0x05, 0x06 } };
This code uses function C99 called designated initializers . As you noticed, this function is not available in C ++ and C ++ 11.
As indicated in this answer , you should use the C compiler for the C code. You can still associate it with your C ++ application. You can use cmake to complete the build configuration for you. A simple example:
#ifndef MYHEADER #define MYHEADER typedef struct { int i, j; } test_t; extern test_t t; #endif
#include "f1.h" test_t t = { .i = 5, .j = 6 };
extern "C" { #include "f1.h" } #include <iostream> int main() { std::cout << ti << " " << tj << std::endl; }
# CMakeLists.txt add_executable(my_executable f0.cc f1.c)
just run mkdir build; cd build; cmake ..; make mkdir build; cd build; cmake ..; make mkdir build; cd build; cmake ..; make from your source directory.
moooeeeep
source share