cancel
Showing results for 
Search instead for 
Did you mean: 

No code generated for inline function call

Andrew Neil
Super User

There is no code generated for the led_rgb_toggle() call here:

AndrewNeil_0-1751021380876.png

led_rgb_toggle() is an inline function:

static inline void led_rgb_toggle( GPIO_PinState r_state, GPIO_PinState g_state, GPIO_PinState b_state )
{
#if defined PROJECT_WITH_RGB_LEDS
    if( r_state ) HAL_GPIO_TogglePin( LED_R_GPIO_Port, LED_R_Pin );
    if( g_state ) HAL_GPIO_TogglePin( LED_G_GPIO_Port, LED_G_Pin );
    if( b_state ) HAL_GPIO_TogglePin( LED_B_GPIO_Port, LED_B_Pin );
#endif
}

 

PROJECT_WITH_RGB_LEDS is defined in the Project defines (name has been changed for confidentiality):

AndrewNeil_2-1751022078656.png

 

It is working in other places.

Why would there be no code generated here?

 

This is CubeIDE v1.13.0 on Win 11

There are no build errors or warnings.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Super User

It was the Optimiser:

Turns out my definition of RGB_COLOUR_ALL was wrong, and actually equated to "none".

So the optimiser spotted that the call did nothing - and left it out!

As it should.

 


@Andrew Neil wrote:

It is working in other places..


Actually, it wasn't:

I had tried setting a breakpoint in led_rgb_toggle(), and it seemed that breakpoint was being hit.

What I hadn't noticed was that the place the breakpoint actually hit wasn't in led_rgb_toggle() - it was in another nearby inline function, with a similar name.

In fact, led_rgb_toggle() was not being used anywhere else in the Project.

So another misdirection by the Optimiser.

 

Optimisation level was -Og.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

View solution in original post

1 REPLY 1
Andrew Neil
Super User

It was the Optimiser:

Turns out my definition of RGB_COLOUR_ALL was wrong, and actually equated to "none".

So the optimiser spotted that the call did nothing - and left it out!

As it should.

 


@Andrew Neil wrote:

It is working in other places..


Actually, it wasn't:

I had tried setting a breakpoint in led_rgb_toggle(), and it seemed that breakpoint was being hit.

What I hadn't noticed was that the place the breakpoint actually hit wasn't in led_rgb_toggle() - it was in another nearby inline function, with a similar name.

In fact, led_rgb_toggle() was not being used anywhere else in the Project.

So another misdirection by the Optimiser.

 

Optimisation level was -Og.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.