0

I am getting the following error #error cpstm8 main.c missing prototype, but what I do not understand is the reason that I am receiving it, I declared the prototype of my function on the top and this error still keep happening, maybe I am missing something, the code follows below.

In my code, I want to gather the data coming from USB, save it in a variable for processing it later.

int * UART1_ReceiveBytes();

void main(void)
{
    while (TRUE)
    {   

        int * p;
        p = UART1_ReceiveBytes();
    }
}

int * UART1_ReceiveBytes()
{
    int i = 0;
    int buf [3] = {0x30, 0x30, 0x30};

    if (UART1_GetFlagStatus(UART1_FLAG_RXNE) != RESET) 
    {
        do
        {
            buf[i] = UART1_ReceiveData8();
            i++;
            delay_ms(10);
        }while(i != 3);

        UART1_ClearFlag(UART1_FLAG_RXNE);
    }
    return buf;
}

I am using COSMIC as a compiler since I am programming STM8 I follow the solution that @Eraklon gave (int * UART1_ReceiveBytes(void);) This solved the problem.

I would like to know if declaring void is just about the compiler or there is some specific rule? Most examples that I was looking declared the prototype like this (int * UART1_ReceiveBytes();)

Ghedim
  • 1
  • 3
  • 4
    Try declare it like this maybe `int * UART1_ReceiveBytes(void);`. And where are the other functions declarations? Can you mark with a comment on which line the error happen? Since the whole snippet code is like 30 line so we dont know where line 47 are. – Eraklon Mar 19 '20 at 09:27
  • @Eraklon About the error line, I deleted some lines that were not related to this error, otherwise, the code would be too long – Ghedim Mar 19 '20 at 09:41
  • Unrelated to the compiler error, you have a severe beginner bug in there, namely returning a pointer to a local variable. – Lundin Mar 19 '20 at 11:53

1 Answers1

0

I would like to know if declaring void is just about the compiler or there is some specific rule? Most examples that I was looking declared the prototype like this (int * UART1_ReceiveBytes();)

It is a compiler dependent case, where, In GCC compiler it won't show any errors, It just ignore them.

Including "void" in the function prototype will specify that, no parameters should be passed while calling the function. By mistakenly, if programmer passes any parameter, During compilation phase It will check the prototype and will throw an error stating that "Function should not contain parameter".

Some compilers might take them serious (COSMIC) and some compiler may not (GCC).

  • No it isn't compiler-dependent. Empty parameter list is listed as an obsolete feature (C17 6.11.6) but it has not been removed from the language yet. Compliant compilers _must_ still support it (for now). – Lundin Mar 19 '20 at 11:56
  • That being said, COSMIC might not follow the C standard, or need a "strict" option to be enabled. Been over a decade since I used that one, so I don't remember. – Lundin Mar 19 '20 at 11:58