sudhir033198
asked on
Rpc binding vector
In microsoft rpc Rpc_Binding_vector is a data structure, defined in header rpcdce.h. It contains two elements, 1. count showing number of binding handles in binding handle array 2. array of binding handles
In include file rpcdce.h the array size has been given as 1.
My doubt is it any way possible for a binding vector to have more than one binding handle ? if yes how?
In include file rpcdce.h the array size has been given as 1.
My doubt is it any way possible for a binding vector to have more than one binding handle ? if yes how?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello???
struct X
{
long count;
int elements[1];
};
The thing to remember is that the difference between "real macho" languages like C and wimpy Wirth languages is that in C it is legal, moral and accepted to lie to the compiler.
C allows accessing out-of-bounds array elements. The following code is legal:
struct X x;
x.elements[0] = x.elements[42] = x.elements[-1000];
The compiler will happily generate code to access the n'th element, whatever n is.
So, the tricky part is allocating enough elements. Static and automatic allocations will not work (obviously) but then, there's malloc().
Let's write a function that will return a pointer to a dynamically allocated structure with n elements (modulo typing errors):
struct X * AllocateStruct(int n)
{
struct X *p = (struct X *) malloc(sizeof(long) + n * sizeof(int));
p->count = n;
return p;
}
And use it thus:
struct X *px;
px = AllocateStruct(100);
/* Do some stuff involving px */
free(px);
OK?