FDEV_SETUP_STREAM in C++(ATmel Studio)

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

i use the declaration in atmel studio (file c):   It works

   static FILE mydata=FDEV_SETUP_STREAM(ili9341_putchar_printf, NULL, _FDEV_SETUP_WRITE);   -

 

but when i use it in  Atmel studio (file C++) : there error compilation

 

when i compile the code, this error is display

 

    Error  sorry, unimplemented: non-trivial designated initializers not supported    

 

Please Help Me

 

Thanks

 

 

This topic has a solution.
Last Edited: Tue. Sep 22, 2020 - 06:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note - i havent looked into this too deeply, but you have stumbled across a difference between c and c++. The simple solution is to put the code into a .c file. Be aware of c++ name mangling when mixing c and c++ files. Read up on extern “c”

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

idir2020 wrote:
Error  sorry, unimplemented: non-trivial designated initializers not supported

That's a C++ language thing.

 

"Designated initalisers" are about initialising the fields in a struct by name - rather than just by position - and C++ does not support this.

 

As an extension, GCC provides limited support for "Designated initalisers" - these are the "trivial" cases. You've tried to go beyond that into non-trivial cases.

 

Putting the error message text into google will get you all the details.

 

FDEV_SETUP_STREAM is a macro - presumably it relies upon "Designated initalisers"

 

EDIT

 

https://www.avrfreaks.net/forum/fdevsetupstream-c

 

EDIT 2

 

Here is the definition of FDEV_SETUP_STREAM - from stdio.h:

#define FDEV_SETUP_STREAM(p, g, f) \
	{ \
		.put = p, \
		.get = g, \
		.flags = f, \
		.udata = 0, \
	}

The "designations" of the initialisers are highlighted.

 

so when you write 

static FILE mydata=FDEV_SETUP_STREAM(ili9341_putchar_printf, NULL, _FDEV_SETUP_WRITE);   -

the preprocessor expands that to

static FILE mydata=
	{
		.put   = ili9341_putchar_printf,
		.get   = NULL,
		.flags = _FDEV_SETUP_WRITE,
		.udata = 0,
	};

 

So you could just do that "manually" - as shown in #10 in the above-mentioned thread

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Sep 21, 2020 - 08:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


This is why there are actually two ways to setup streams shown in the manual:

 

https://www.nongnu.org/avr-libc/...

 

does indeed use designnated initializers which are not supported in C++ but for that you can use the dynamic (runtime) setup:

 

https://www.nongnu.org/avr-libc/...

 

As mentioned in the thread Andy linked to you can simply do it "raw":

 

 

but fdev_setup_stream() can simply be used as a "helper" for this:

 

 

That is .cpp and it builds cleanly.

 

(aside: foo() is not related and was something I used in this example file previously to show someone a different thing (how to link to C))

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Evry one

 

Thanks you for your response

 

I will give you a feedback

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello 

THANKS YOU 

I use this code , it work now

____________________________________

extern "C" {
    #include ...
    #include ...
};

 

int main(void){

    FILE mydata;
    mydata.put = ili9341_putchar_printf;
    mydata.get = NULL;
    mydata.flags = _FDEV_SETUP_WRITE;

_____________________________

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

idir2020 wrote:
it work now

thanks for feedback; now please mark the solution - see Tip #5 in my signature(below) for instructions

 

Also see Tip #1 for how to properly post source code

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, thanks for this detail.