AVR C ++ uint32_t weird behavior

uint32_t a = 65536;
uint32_t b = 1 << 16;

Why a != bhere but

uint32_t a = 65536;
uint32_t b = 65536;

here a == balthough it should be technically the same?

I use CLion as IDE and CMake 3.7.1 with Arduino CMake.

+4
source share
2 answers
uint32_t b = 1 << 16;

as you noticed, this disappears unless you first drop 1 into a 32-bit integer:

A literal 1is the default integer type in your compiler. I don’t know which one, but it is either 8 or 16 bits of int.

Now suppose it's 16 bits. When you change 1 time 16 times, you just ... well, that doesn't make sense. So make your 132-bit int first, and then slide it.

+5
source

1 uint32_t, , .

+2

Source: https://habr.com/ru/post/1683128/


All Articles