Newbie question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newbie question

1,941 Views
gbaars
Contributor I
In a first try on the DEMOJM with MCF51JM128
(blinking a led) the watch dog is disabled.
Before blinking loop the line
 
MCGC2 = MCGC2 && 0b11111111;
 
seems to double the busfreq (why effect at all?)??
Labels (1)
0 Kudos
Reply
5 Replies

589 Views
gbaars
Contributor I
Works fine.
0 Kudos
Reply

589 Views
JimDon
Senior Contributor III
Well, some would recommend that you not turn off warnings, and that you explicitly cast to eliminate the warnings.

If fact, if you need to comply with a standard, like MIRSA, you are not permitted to turn warnings off.

Although it may seem warnings are just an annoyance, sometimes they do point to a problem.
I have used pragmas to disable certain warnings for a small block of code, but never disable them completely.
Also, if you work professionally, you may be required to leave them on, so you should learn about them.

Code that compiles clean with warnings off is not code that really is clean, and if you decide later to turn them back on you will have a big job to go fix them all.


0 Kudos
Reply

587 Views
gbaars
Contributor I
MCGC2 = MCGC2 & 0b11111111;
 
does not compile (int to unsigned char conversion error).
0 Kudos
Reply

589 Views
RichTestardi
Senior Contributor II

Hi,

 

> MCGC2 = MCGC2 & 0b11111111;
>
> does not compile (int to unsigned char conversion error).

 

Arithmetic operators produce integer results by default, and an implicit cast from an integer to an unsigned char produces a warning/error by default.

 

You might try an unsigned char operator:

 

  MCGC2 &= 0b11111111;

 

Or an explicit cast:

 

  MCGC2 = (unsigned char)(MCGC2 & 0b11111111);

 

Or just disable the error/warning:

 

  turn off "Implicit Arithmetic Conversions" in project settings -> C/C++ Warnings

 

I actually run with that error/warning disabled.

 

-- Rich

0 Kudos
Reply

589 Views
JimDon
Senior Contributor III

Because && resolves to true or false.

Did you mean '&'?

0 Kudos
Reply