12-23-2019 04:01 AM
GOOD DAY,
how to clear the warning:
implicit conversion loses integer precision: 'unsigned int' to 'unsigned char' in LabWindows/cvi 2017
warning: implicit conversion loses integer precision: 'int' to 'unsigned char'
12-23-2019 05:33 AM - edited 12-23-2019 05:36 AM
You are assigning the value of one variable to another but their data type don't match: the source is an unsigned int variable (4-bytes long) which is passed to a unsigned char (1-byte long). The warning tells you that you may lose some data if the source has a value > 0xff.
Depending on your situation, you may need to either:
1. change the uchar variable to uint type if you are expecting higher values
2. change the uint to a uchar variable if only single-byte values are expected
3. cast the uint to a uchar this way (but be warned that this masks the warning so is at your own risk and responsibility)
unsigned int ui;
unsigned char uc;
ui = 37;
uc = (unsigned char)ui; // Safe
ui = 1000;
uc = (unsigned char)ui; // WRONG!!!
(Ok you could also set CVI to ignore the warning but I don't suggest you to do so: warnings are meaningful and can help you in solving some coding problem)