cancel
Showing results for 
Search instead for 
Did you mean: 

Defining function inside function and comparisons like (0 < myVar < 100) does not give compile errors

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.

1 REPLY 1
KnarfB
Super User

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