Hi,
I'm having trouble compiling a C file with the char16_t
type, which should be a C11 compatible type. I do not have this problem when I compile a .ino project file with this type. I'm using VSCode with a automatically generated c_cpp_properties.json
file. Within the file there are 2 properties defined: { "cStandard": "c11", "cppStandard": "c++11" }
and I can also find the "__CHAR16_TYPE__=unsigned int"
in the defines property array of the same file.
Lets give my an example. My test project consists of 2 files; a myproject.ino file and a test.c file in the same folder. The myproject.ino file contains
static char16_t arr[] = u"Καλημέρα";
static char16_t banana = u'🍌';
extern "C" char test(char16_t ch);
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(arr[0]);
Serial.print(test(banana));
}
The test.c
file contains:
#include <Arduino.h>
char test(char16_t ch)
{
return (char)ch & 0xff;
}
If I change the char16_t
type to the uint16_t
type, it compiles just fine.
There is no <uchar.h>
header file in the arduino library to be found. I did vind the atomic_char16_t type in <stdatomic.h>
I'm not sure what to do next. To be honest I believe that C
files are not compiled with the C11 standard but instead the C99 standard. But looking into the arduino build folder I found the following in the compile_commands.json
.
[
{
"directory": "c:\\Users\\Jipinx\\Documents\\Arduino\\libraries\\protoduino",
"arguments": [
"C:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++",
"-c",
"-g",
"-Os",
"-w",
"-std=gnu++11",
"-fpermissive",
"-fno-exceptions",
"-ffunction-sections",
"-fdata-sections",
"-fno-threadsafe-statics",
"-Wno-error=narrowing",
"-MMD",
"-flto",
"-mmcu=atmega328p",
"-DF_CPU=16000000L",
"-DARDUINO=10607",
"-DARDUINO_AVR_UNO",
"-DARDUINO_ARCH_AVR",
"-IC:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino",
"-IC:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\standard",
"C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\myproject.cpp",
"-o",
"C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\myproject.cpp.o"
],
"file": "C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\myproject.cpp"
},
{
"directory": "c:\\Users\\Jipinx\\Documents\\Arduino\\libraries\\protoduino",
"arguments": [
"C:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc",
"-c",
"-g",
"-Os",
"-w",
"-std=gnu11",
"-ffunction-sections",
"-fdata-sections",
"-MMD",
"-flto",
"-fno-fat-lto-objects",
"-mmcu=atmega328p",
"-DF_CPU=16000000L",
"-DARDUINO=10607",
"-DARDUINO_AVR_UNO",
"-DARDUINO_ARCH_AVR",
"-IC:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino",
"-IC:\\Users\\Jipinx\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\standard",
"C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\test.c",
"-o",
"C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\test.c.o"
],
"file": "C:\\Users\\Jipinx\\Documents\\Arduino\\build\\sketch\\test.c"
}
]
I hope someone can help me with this, because i'm beginning to get bald...
Regards,
Jipinx.