Incomplete array element type as function argument (C mode)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am trying to compile the following code:
------------------------------------------------------------------------------------------------
#include <stdio.h>

typedef struct my_struct My_struct;


void f1(My_struct *a, unsigned n)
{
    if (a)
        printf("n = %u\n", n);
}


void f2(My_struct a[], unsigned n)
{
    if (a)
        printf("n = %u\n", n);
}


int main()
{
    printf("Hello World");

    return 0;
}
------------------------------------------------------------------------------------------------

Compilation fails with the following error:

main.c:21:19: error: array type has incomplete element type ‘My_struct’
{aka ‘struct my_struct’}
   21 | void f2(My_struct a[], unsigned n)

If I delete f2, the code compiles without any errors.

I used the compiler available here:
https://www.onlinegdb.com/online_c++_compiler
I have selected C mode.

Why doesn't f2 compile? I was under the impression that there is no
difference between f1 and f2.

Indeed, the above code compiles without any errors on Visual Studio (2019).

Thanks,




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux