set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

Postby chromebin » Thu May 10, 2018 11:52 pm

I get the error "pointer targets in initialization differ in signedness [-Werror=pointer-sign]" due to using unsigned char as the char type. So among other things, string literals assigned to uint8_t arrays cause warnings.

In a previous setup I had succeeded in configuring Eclipse to set the default char type to unsigned. However I forgot to write it down, and now I have a new setup, an avalanche of warnings, and I just spent an hour searching the internet in vain to correct this :(

What I do find are instructions for an unknown version of Eclipse, where one goes to Project Properties, C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> *Miscellaneous* -> Other Flags and puts in "-funsigned-char" for GCC. However in Eclipse Oxygen the dialog has changed and Miscellaneous is no longer to be found. Settings now has 2 tabs: "Binary Parsers" and "Error Parsers".

I tried adding the "-funsigned-char" to all these entries in the Workspace Settings (Discovery tab), but I observed no effect.

Maybe someone knows how to configure this? That would be a big relief!

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

Postby ESP_Angus » Fri May 11, 2018 3:13 am

If you use ESP-IDF then Eclipse is building via the ESP-IDF build system (with GNU Make). So you have to make any change like this in the ESP-IDF build system files.

You can add a line "CFLAGS += -funsigned-char" to the component.mk file for your components where you want this compiler behaviour.

The full reference for the build system is here:
https://esp-idf.readthedocs.io/en/lates ... ystem.html

You could also theoretically add this line to the project Makefile to have it apply to the entire project. This is not recommended as you may get unexpected behaviour from internal parts of ESP-IDF that expect to deal with signed chars.

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

Postby chromebin » Fri May 11, 2018 11:17 am

ESP_Angus wrote:If you use ESP-IDF then Eclipse is building via the ESP-IDF build system (with GNU Make). So you have to make any change like this in the ESP-IDF build system files.
Yes I do use Eclipse. Thank you for your kind reply. I wil try this.

Note that the installation tutorial is out of date with the new Eclipse (Oxygen, as tested on Windows), as it doesn't pull in the paths correctly, causing beginners much pain. I'll continue in another post.

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

Postby chromebin » Fri May 11, 2018 11:40 am

I added the CFLAGS, I now have this component.mk file in the "main" folder:

Code: Select all

#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)



COMPONENT_ADD_INCLUDEDIRS += \
	drivers
	
COMPONENT_SRCDIRS += \
	drivers
	    
CFLAGS += \
    -funsigned-char    
However, I see no change. Just to be sure I rebooted Eclipse. No changes.

chromebin
Posts: 77
Joined: Wed Feb 07, 2018 3:53 pm

Re: set default char type as unsigned (GCC -funsigned-char flag) in Eclipse

Postby chromebin » Fri May 11, 2018 6:59 pm

This [-Werror=pointer-sign] => '-funsigned-char' issue causes an error, so I can no longer flash the project, so I'm stuck. Changing everything to 'char' is not an option (and the concept of possibly negative chars makes no sense to me).

Anyone has an idea as to how to solve this (see top post)?

---------------------------------------------------------

UPDATE: there was a 2nd cause: some multi-dimensional string arrays were wrongly declared. Don't know how things compiled before though. Really don't. For those that happen to find this post and have similar problems:

const char * messages[2][3] = {
{ "a", "bb", "ccc",},
{ "A", "BB", "CCC"}
};

Which is simply a 2D array of string pointers.

Problem solved.

Who is online

Users browsing this forum: No registered users and 80 guests