6.2.5
At various points within a translation unit an object type may be incomplete (lacking sufficient information to determine the size of objects of that type).
Also
6.2.5 19) The void type comprises an empty set of values; it is an incomplete object type that cannot be completed.
And
6.5.3.4 The sizeof operator shall not be applied to an expression that has function type or an incomplete type,
But Visual Studio 2010 prints 0
for
printf("Size of void is %d\n",sizeof(void));
My question is 'What are incomplete types
'?
struct temp
{
int i;
char ch;
int j;
};
Is temp
is incomplete here? If yes why it is incomplete(We know the size of temp)? Not getting clear idea of incomplete types
. Any code snippet which explains this will be helpful.
Your struct temp
is incomplete right up until the point where the closing brace occurs:
struct temp
{
int i;
char ch;
int j;
};// <-- here
The structure is declared (comes into existence) following the temp
symbol but it's incomplete until the actual definition is finished. That's why you can have things like:
struct temp
{
int i;
char ch;
struct temp *next; // can use pointers to incomplete types.
};
without getting syntax errors.
C makes a distinction between declaration (declaring that something exists) and definition (actually defining what it is).
Another incomplete type (declared but not yet defined) is:
struct temp;
This case is often used to provide opaque types in C where the type exists (so you can declare a pointer to it) but is not defined (so you can't figure out what's in there). The definition is usually limited to the code implementing it while the header used by clients has only the incomplete declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With