
problem with pointer to pointer to void
Quote:
>Hi All,
>I have a buffer allocation function that was declared as follows:
> int MyBuffAlloc(size_t size, void **pBuff);
This type of interface is a sign of trouble. You cannot use the type void ** as
a generic pointer-to-any-pointer. This issue is covered in the comp.lang.c FAQ.
Quote:
>8 RetCode = MyBuffAlloc(sizeof(MyStruct), &((void *)(pBuff)));
The result of a cast expression is not an lvalue and so has no address.
The expression (void *) pBuff means to convert the lvalue pBuff into
the value stored in the object that it designates, and then to convert
that value to (void *). By the time this happens, the lvalue property
has been stripped away.
Quote:
>......
>My compiler didn't complain about the call in line 8.
Your compiler is broken or is being operated in some non-conforming mode in
which it is possible for the results of cast expressions to behave as lvalues.
Find out how to make your compiler conform to ANSI C as closely as it can. In
the case of the GNU C compiler, for instance, the -ansi -pedantic options do
this.