cancel
Showing results for 
Search instead for 
Did you mean: 

Assignement binary value to a variable dosn't work

nico23
Associate III

As title suggest.

If I do

int my_var;
my_var = 0b01;

 my_var stays 0

Instead with

int my_var;
my_var = 0x01;

Everything works

 

STM32CubeIDE

Version: 1.14.1

Build: 20064_20240111_1413 (UTC)

15 REPLIES 15

That could be the issue as I'm using IAR as well and I've been using the 0b notation forever. How do I check if CubeIDE has it implemented?

So I have a data structure in the form of

 

struct registri{
	uint16_t reg1;
} data_read;

 

And I use it inside a function like

 

void com_gateway(struct registri *dati){
   dati->reg1 = 0b01;
}

 

Even if I use a switch case like

 

switch(dati->reg1) {
   case 0b0:
   break;
   case 0b1:
   break;
}

 

Seems to not match the cases. Instead, using 0x0 and 0x1 everything works fine (or 0, 1, 2 etc)

I'm using an STM32F091


@nico23 wrote:

How do I check if CubeIDE has it implemented?


You would get an error (or, at least, a warning).

Again, you need to show a minimum but complete example which illustrates the issue.

Code snippets out of context tell us very little - especially when they're not even the code you're actually running.

The issue here is that on the MCU GG Compiler I've the -fcommon flag active because GCC10 enforce some warning as error and won't make compile/link

Please refer to this. So, I could be warnings/errors, but maybe they're stripped because the flag?

As that link says, the situation arises from bad code - so would be better to fix the underlying issue that mask it behind -fcommon.

Similarly with binary constants - they are* a non-portable extension, so best avoided if you don't want to run into problems when porting to new tools.

 

* Or were until very recently.