This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

"var << 1" gets optimized away

hi all,

I have the following line in my code:

PortVal << 1;

When I compile using c51 v6.12, I get the following warning assocaiated with that line:

"warning C275: expression with possibly no effect"

When I load this into my emulator, "PortVal << 1" has been optimized away.

I know that << 1 is the same as *2, and when I use *2, the compilier is happy, but I like << 1 because it helps readability.....


Does anyone know why << 1 causes that warning or how to prevent it from being optimized away?

Thanks
Steve

Parents
  • The warning has nothing whatsoever to do with << vs. * --- you should actually have got it for the *2 case, too.

    The warning complains about "no effect" because that's what this really is: a statement that doesn't do anything. It computes a value that's not used for anything. This can usually have two reasons, one of which is an outright bug in the code. The other would be an expression being compute only for its side effects. But the expression shown doesn't have any, so that's pretty much ruled out.

    Conclusion: that warning is valid. You should probably re-write that line or remove.

Reply
  • The warning has nothing whatsoever to do with << vs. * --- you should actually have got it for the *2 case, too.

    The warning complains about "no effect" because that's what this really is: a statement that doesn't do anything. It computes a value that's not used for anything. This can usually have two reasons, one of which is an outright bug in the code. The other would be an expression being compute only for its side effects. But the expression shown doesn't have any, so that's pretty much ruled out.

    Conclusion: that warning is valid. You should probably re-write that line or remove.

Children