-
void datatype
ok ... the trouble started with sizeof(void) = 1
on similar terms sizeof empty class/structure in C++ is also 1
Bjarne Stroustrup's FAQ reasons: "To ensure that the addresses of two different objects will be different. " taken from here
but I cannot use the same reasoning for void ... since I cannot create variables of void type
void x ; <does not hold>
-
> the trouble started with sizeof(void) = 1
Says who?
Code:
#include <stdio.h>
#include <stdlib.h>
int main ( ) {
printf("%d\n", sizeof(void) );
return 0;
}
gcc reports
foo.c:5: warning: invalid application of `sizeof' to a void type
vc6 reports either
foo.c(5) : warning C4034: sizeof returns 0
foo.c(5) : error C2070: illegal sizeof operand
You can't have a variable with void type, even if your compiler apparently gives it a non-zero size.
> on similar terms sizeof empty class/structure in C++ is also 1
But C can't have an empty struct.
-
thank you! , solves all the troubles
btw... what is the difference between -pedantic and -Wall arguments in gcc ?
I have been using -Wall instead of -pedantic ... so the warnings were bypassed
-
The gcc manual page explains all.