Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Initializing struct (in C++)

Initializing struct (in C++)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++visual-studiodata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    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,
    };

    L 1 Reply Last reply
    0
    • V Vaclav_

      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,
      };

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups