Example error message: “ap-main.c:189:: warning: (759) expression generates no code”

Example that will cause it:

#define POWER_CONTROL_0(state)		(state ? (LATCbits.LATC0 = 0) : (LATCbits.LATC0 = 1))  //1:0, 0=on

	POWER_CONTROL_0(1);

This error is not usually generated by compilers, but is for XC8 and Microchip supported it with:

The compiler detects that the condition is true, eliminates the code generation for the condition and produces a warning to this effect.

No code is generated for the true condition.

However code is generated for all the statements inside the true condition.

This optimization reduces the code size, as it removes checking for condition and branching, which might otherwise take a couple of instructions.

The code for checking True or false is not generated in ternary operator in this case and hence the warning. Compiler has optimized to eliminate the checking of true or false.

Follow on after arguing this was an extremely confusing / misleading warning to be generated:

I discussed with the compiler developers.

The compiler will try to issue as many warnings as possible for the code so that the programmer is aware.

It is possible that in many of the cases, a simple typo has resulted in this situation, where the code does nothing and which is what the warning is asking the programmer to confirm. Sometimes there are situations (and many of them) where expressions like these don’t generate any code, and it helps the programmer to decide whether they want to rewrite their code, to avert the warnings or continue with these warnings.

This warning can be disabled, by changing the warning level to 0.

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *