1

I am writing 'C' using Visual Studio 2019 community with VisualGDB for an embedded ARM based project (STM32). VisualGDB shows its error reporting uses the default gnu11 standard.

EDIT: I have made this code a little more complete:

typedef int(*CMD_Type)();
int CMD_0() {  return 0; }
int CMD_1(float val) {     return 1; }
int CMD_2(float val1, float val2) {    return 2; }
int DoSomething ()
{
    CMD_Type c = CMD_1;
    if (c == CMD_2)
    {
        return c(1, 2);
    }
}

I get red squiggles under the "==" saying that it Cannot apply binary '==' to <anonymous> (*)()> and <anonymous>(*)(int)

I also get red squiggles under two argument that I call c with when I call it with two parameters: function has zero parameters but is called> with two.

This compiles with no errors and works.

My understanding is that even though CMD_Type is type-def'ed as a pointer to a function that returns an integer and takes in no arguments, it is simply a pointer to a function and any arguments just get pushed onto the heap so this works. So I get why the compiler / intellisense is complaining.

  1. Is this ok?
  2. Can I turn off this warning if it compiles anyway?

FYI: I inherited this code :).

Any help would be appreciated.

Thanks -Ed

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
Ed Landau
  • 966
  • 2
  • 11
  • 24

0 Answers0