Re: GetAdapapters info asking for a wrong-size buffer?



villiros@xxxxxxxxx wrote:

> On a machine with more then one adapter, GetAdaptersInfo rightfully
> complains about a small buffer and steps into the if. However, the
> value put into outBufLen does not divide evenly by sizeof
> IP_ADAPTER_INFO.

What you are seeing is such a usual C idiom that you have to familiarize
yourself with it. A function has to return an array of complicated data
structures. You want the caller to allocate memory but asking him to
allocate each piece separately will simply be unmanageable. Instead you ask
for a one large chunk that will be enough to contain everything you need to
return and place your results in it. Unless your array items are completely
self-contained there will be no relationship between the memory size you
request and the count of items in array.

The thing to remember is to "give it what it asks for" and not try to count
sizeofs and such.

--
Eugene
http://www.gershnik.com


.



Relevant Pages

  • Re: A couple of things from H&S
    ... expression of array type decays to a pointer to the array's first ... element *unless* it's in one of three contexts: the operand of sizeof, ... is quite obvious, p is the pointer. ...
    (comp.lang.c)
  • Re: Null terminated strings: bad or good?
    ... specified type, it must not be possible to use callocto allocate such ... allocate such an array, that still doesn't make it possible for ... For any object that you can actually define in your program, with either static or automatic storage duration, "sizeof object" is supposed to give the size of that object; the standard provide no exceptions to this requirement. ...
    (comp.lang.c)
  • Re: C Strings
    ... sizeof ... More generally, given any array object, we can find a pointer to ... works quite as well for C99 as it did for C89, ...
    (comp.lang.c)
  • Wording glitch: sizeof array vs. sizeof (array)
    ... A parenthesized expression is a primary expression. ... Except when it is the operand of the sizeof operator or the unary ... & operator, or is a string literal used to initialize an array, an ...
    (comp.std.c)
  • Re: Question about sizeof
    ... Mark double $$ ... This is true in any situation, not only with sizeof ... Cant you keep original values in the array instead of the variable names? ... -Each type of discography is associated with an array that contains ...
    (comp.lang.php)