Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: conversion to 'u8int' from 'int' may alter its value, etc

Tags:

c

So lately I've been writing stuff where I have to use a lot of uint8/uint16 and mix them with each other and integer literals. So I'm getting warnings such as:

warning: conversion to 'u16int' from 'int' may alter its value

Code:

u16int attr = attr_byte << 8;

I like compiling with lots of warnings on. I do not like getting warnings. Is there some (preferably clean) way to fix this?

like image 945
Tom Carrick Avatar asked Jan 15 '23 07:01

Tom Carrick


1 Answers

You can always cast:

u16int attr = (u16int)(attr_byte << 8);

I.e. you tell the compiler you know what you are doing.

like image 88
Florian Avatar answered Feb 02 '23 08:02

Florian