Hello all,
As we know you can't return arrays from functions in programming language C. I am working on an open source code base written in C. While working on one of its function, I wanted to be sure if I have correctly understood the return value of the following function. Can someone please help me understand what exactly below function bucket_straw2_choose is returning?
Code:
static int bucket_choose (const struct crush_bucket_straw2 *bucket, int x, int r,
const struct crush_choose_arg *arg, int position) {
__u32 *weights = get_choose_arg_weights(bucket, arg, position);
__s32 *ids = get_choose_arg_ids(bucket, arg);
for (i = 0; i < bucket->h.size; i++) {
dprintk("weight 0x%x item %d\n", weights[i], ids[i]);
if (weights[i]) {
--
draw = generate_exponential_distribution(bucket->h.hash, x, ids[i], r,
weights[i]);
} else {
draw = S64_MIN;
}
if (i == 0 || draw > high_draw) {
high = i;
high_draw = draw;
}
}
return bucket->h.items[high];
}
struct crush_bucket {
__s32 id;
__u16 type;
__u8 alg;
__u8 hash;
__u32 weight;
__u32 size;
__s32 *items;
};
struct crush_bucket_straw2 {
struct crush_bucket h;
__u32 *item_weights;
};