Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of ANYSIZE_ARRAY in <winnt.h>?

What's the purpose of ANYSIZE_ARRAY, located in WinNT.h?

I see an MSDN blog post about it from 2004 but it doesn't make sense to me.

like image 990
jglouie Avatar asked Feb 08 '12 15:02

jglouie


2 Answers

I assume you are talking about this blog post.

It is often used when a variable-sized (unknown at compile time) array is part of a struct:

typedef struct {
    int CommonFlags
    int CountOfThings;
    THING Things[ANYSIZE_ARRAY]; //Things[1];
} THINGSANDFLAGS;

To work with those structures you often first call the desired API to get the size of the data, then allocate a block of memory big enough and finally call the same API again so it can fill in the data...

like image 65
Anders Avatar answered Oct 05 '22 22:10

Anders


From this page:

In C, a variable-size array is declared as a[1] or a[ANYSIZE_ARRAY], where ANYSIZE_ARRAY is defined as 1. Then it is used as if it were bigger.

like image 32
Smi Avatar answered Oct 05 '22 21:10

Smi