Visual Studio 2019 compile errors

Hi,

I’m trying to use the Visual Studio SDL LVGL Simulator project with the lvgl master from Github.

I get the following error for lv_color.h:482

“Error C4576 a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax”

The Problem is with the following define:
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{(b8 >> 3) & 0x1FU, (g8 >> 2) & 0x3FU, (r8 >> 3) & 0x1FU}})

Is this a bug in LVGL or can I fix this somehow?

I just checked the simulator in Visual Studio, with the master branch (for main and subrepos), and it’s running normally.

Maybe check that you have updated (and checked out) the master branch in all submodules of the project?

Looks like it might an issue with Visual Studio’s C++ support. This feature appears to be unsupported in C++: https://stackoverflow.com/a/33271165

It works with GCC C++ compiler. It only throws this error when I’m compiling with VisualStudio. (We are using LVGL functions from C++).

Our G++ Version: gcc version 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437] (GNU Tools for ARM Embedded Processors 6-2017-q2-update).

The Error is only with LV_COLOR_MAKE. Maybe if we wrap it in a function so we don’t have it in the header?

I don’t think that will help, because it appears that Visual Studio doesn’t support this syntax at all in C++ mode. We might need to fix that. @kisvegabor?

Is there a way to initialize a struct in a C header file?

E.g. is it working?

#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){.ch.blue = (b8 >> 3) & 0x1FU, .ch.green = (g8 >> 2) & 0x3FU, .ch.red = (r8 >> 3) & 0x1FU})

@kisvegabor

Thank you for your reply.

Your suggestion does not work with VisualStudio C++ compiler. I’m going to switch to mingw or cygwin gcc/c++ compiler.

If you would like to keep using Visual Studio, I would suggest compiling these files as C files (and not C++ files). The rest of your program can still be C++; you just need to configure the IDE so that it does not treat LittlevGL as a C++ program.

We had previously discussed officially deprecating this mode of compilation (see these comments), because it relies on the assumption that C and C++ are the same language (and they are not). It also adds complexity to our testing as we have to test the code on both a C and C++ compiler.

@kisvegabor I just thought of something. Can the Arduino IDE compile LittlevGL as C source code or does it force C++?

@embeddedt

If you include the header lv_color.h in a CPP file then those Macros get compiled with the C++ compiler. Using LVGL with GCC/G++ works 100% but not with the Microsoft C++ compiler. The only issue is with VC++. If you configure The VisualStudio project to use GCC/G++ (MSYS2, Mingw, Cygwin etc) then you can use lv_color.h in C++ code.

Perhaps we should just condition the LV_COLOR_MAKE macro on the code being C and not C++, since it relies on behavior that is only standard in C99 (not C++).

Or we can just remove LV_COLOR_MAKE and use lv_color_make (function) instead. It would prevent to initialize global color variables, but I’m bot sure it’s an issue.