Newbie question

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Newbie question

2,635 次查看
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?)??
标签 (1)
0 项奖励
回复
5 回复数

1,283 次查看
gbaars
Contributor I
Works fine.
0 项奖励
回复

1,283 次查看
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 项奖励
回复

1,281 次查看
gbaars
Contributor I
MCGC2 = MCGC2 & 0b11111111;
 
does not compile (int to unsigned char conversion error).
0 项奖励
回复

1,283 次查看
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 项奖励
回复

1,283 次查看
JimDon
Senior Contributor III

Because && resolves to true or false.

Did you mean '&'?

0 项奖励
回复