Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"warning: narrowing conversion" warning error #16

Open
alexruffell opened this issue Apr 3, 2023 · 2 comments
Open

"warning: narrowing conversion" warning error #16

alexruffell opened this issue Apr 3, 2023 · 2 comments

Comments

@alexruffell
Copy link

alexruffell commented Apr 3, 2023

I keep getting this warning and do not know how to fix it. I don't believe it is due to anything I may have done as I reused the code as-is.

In file included from src/main.cpp:107:
src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)':
src/ld2410_uart.h:217:27: warning: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Wnarrowing]
     char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
                    ~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)':
src/ld2410_uart.h:245:27: warning: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Wnarrowing]
     char cmd[2] = {enable ? 0x62 : 0x63, 0x00};
                    ~~~~~~~^~~~~~~~~~~~~
In file included from src/main.cpp:107:
src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)':
src/ld2410_uart.h:273:33: warning: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Wnarrowing]
     char value[2] = {index, 0x00};
                                 ^

The warning above happens when leaving the framework to the default arduino. Since the code appears to crash my ESP32, I tried IDF and it is now causing the compiler to fail:

In file included from src/main.cpp:93:
src/ld2410_uart.h: In member function 'void LD2410::sendCommand(char*, char*, int)':
src/ld2410_uart.h:46:16: error: 'lowByte' was not declared in this scope
     write_byte(lowByte(len));
                ^~~~~~~
src/ld2410_uart.h:47:16: error: 'highByte' was not declared in this scope
     write_byte(highByte(len));
                ^~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)':
src/ld2410_uart.h:217:27: error: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Werror=narrowing]
     char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
                    ~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)':
src/ld2410_uart.h:245:27: error: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Werror=narrowing]
     char cmd[2] = {enable ? 0x62 : 0x63, 0x00};
                    ~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setMaxDistancesAndNoneDuration(int, int, int)':
src/ld2410_uart.h:252:35: error: 'lowByte' was not declared in this scope
     char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00};
                                   ^~~~~~~
src/ld2410_uart.h:252:68: error: 'highByte' was not declared in this scope
     char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00};
                                                                    ^~~~~~~~
In file included from src/main.cpp:93:
src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)':
src/ld2410_uart.h:273:33: error: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Werror=narrowing]
     char value[2] = {index, 0x00};
                                 ^
@DavidSack
Copy link

I am seeing the same thing except it does not seem to crash my ESP32.

@elchanly
Copy link

I stepped into something similar when changing arduino to espidf.
My log: In file included from src/main.cpp:84: src/ld2410_uart.h: In member function 'void LD2410::sendCommand(char*, char*, int)': src/ld2410_uart.h:46:16: error: 'lowByte' was not declared in this scope write_byte(lowByte(len)); ^~~~~~~ src/ld2410_uart.h:47:16: error: 'highByte' was not declared in this scope write_byte(highByte(len)); ^~~~~~~~ src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)': src/ld2410_uart.h:217:27: error: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Werror=narrowing] char cmd[2] = {enable ? 0xFF : 0xFE, 0x00}; ~~~~~~~^~~~~~~~~~~~~ src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)': src/ld2410_uart.h:245:27: error: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Werror=narrowing] char cmd[2] = {enable ? 0x62 : 0x63, 0x00}; ~~~~~~~^~~~~~~~~~~~~ src/ld2410_uart.h: In member function 'void LD2410::setMaxDistancesAndNoneDuration(int, int, int)': src/ld2410_uart.h:252:35: error: 'lowByte' was not declared in this scope char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00}; ^~~~~~~ src/ld2410_uart.h:252:68: error: 'highByte' was not declared in this scope char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00}; ^~~~~~~~ In file included from src/main.cpp:84: src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)': src/ld2410_uart.h:273:33: error: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Werror=narrowing] char value[2] = {index, 0x00}; ^ Compiling .pioenvs/bano/bootloader_support/src/flash_encrypt.o Compiling .pioenvs/bano/bootloader_support/src/secure_boot.o Compiling .pioenvs/bano/bootloader_support/src/flash_partitions.o Compiling .pioenvs/bano/bootloader_support/src/flash_qio_mode.o Compiling .pioenvs/bano/bootloader_support/src/bootloader_flash_config_esp32.o Compiling .pioenvs/bano/bootloader_support/src/bootloader_efuse.o Compiling .pioenvs/bano/bootloader_support/src/idf/bootloader_sha.o cc1plus: some warnings being treated as errors Compiling .pioenvs/bano/bt/controller/esp32/bt.o *** [.pioenvs/bano/src/main.o] Error 1

My pins are 16 and 17 and im using NodeMCU-32s
I've to also tell that, when on arduino, platform warnings just appeared but could compile and it worked, in fact thats what i have now working flawlessly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants