LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

implicit conversion

 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'

0 Kudos
Message 1 of 2
(4,166 Views)

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)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(4,109 Views)