2025-08-01 9:31 PM - last edited on 2025-08-04 1:41 AM by Andrew Neil
Hi,
In CubeIDE it does not generate any compile error,
if function is defined inside function
int function_out(int i)
{
int function_in(int y)
{
}
}
and comparisons is written in format (0 < myVar < 100)
if(0 < myVar < 100)
{
}
As I know these are not allowed in C.
Edited to apply source code formatting - please see How to insert source code for future reference.
2025-08-01 10:36 PM - edited 2025-08-01 10:44 PM
Nested functions are gnu bs accepted by gcc, not ISO C.
Probably inherited from pascal type languages.
The chained comparison is syntactically legal, but gives misleading results.
You may try options like -std=c11 -pedantic -Wall -Wextra -Werror for taming the gnu.
Or switch to clang (STM32Cube further facilitates code development wit... - STMicroelectronics Community)
C:\tmp>clang gnu.c
gnu.c:9:1: error: function definition is not allowed here
9 | {
| ^
gnu.c:13:14: warning: result of comparison of constant 100 with boolean expression
is always true [-Wtautological-constant-out-of-range-compare]
13 | if(0 < myVar < 100)
| ~~~~~~~~~ ^ ~~~
1 warning and 1 error generated.
hth
KnarfB
2025-08-04 1:39 AM - edited 2025-08-04 1:42 AM
@ThusithaSamarasekara wrote:As I know these are not allowed in C.
Not in Standard C but, as @KnarfB said, GCC allows nested functions as an extension:
https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html