-7

==> EXTREME BEGINNER QUESTION FOR EXTREME BEGINNERS <==

Does anyone know why this: void buf[1]; returns this error:

error: array has incomplete element type 'void'.

Is it normal ?

AymenTM
  • 529
  • 2
  • 5
  • 17
  • 1
    `void` is not a datatype. You have to declare an array as a valid datatype. – emsimpson92 Aug 31 '18 at 17:12
  • you cant have an array of void – Mitch Aug 31 '18 at 17:12
  • 1
    @vasia has the answer you're looking for – emsimpson92 Aug 31 '18 at 17:13
  • 2
    @emsimpson92, the standard disagrees with you: "The `void` type comprises an empty set of values; **it is an** incomplete **object type** that cannot be completed" ([C2011 6.2.5/19](http://port70.net/~nsz/c/c11/n1570.html#6.2.5p19), emphasis added). The requirement is that the element type of an array must be a *complete* type, which `void` explicitly is not. – John Bollinger Aug 31 '18 at 17:18
  • My mistake. I guess I've never heard of incomplete/complete types – emsimpson92 Aug 31 '18 at 17:21

2 Answers2

3

You can't declare an array of void types - perhaps you meant to declare an array of void pointers? In this case you would do

void *buf[1];

However, it seems more likely you just want one void pointer?

void *buf;
vasia
  • 1,093
  • 7
  • 18
2

void is not a complete type. It is only used either in a function definition to state that it either takes no parameters or returns no value, or as a generic pointer i.e. void *ptr.

As such, a variable of type void cannot exist.

dbush
  • 205,898
  • 23
  • 218
  • 273