How to decouple a pointer conditional check on link lists?
Hello All,
See the code below. What i'm trying to do is disassociate the condition, so i can re-use the function for different parameters.
Code:
// 1. How can I decouple the fast forward condition?
// 2. How can i change the operator?
// 3. What do I do when type of stop condition for structure comparison is no longer int?
// -------------- Attempt 1
// function
void elem_forward_until(seg_list_elem_t ptr, &ptr->s.t_end##, int stop_condition) {
while (ptr && (ptr->s.t_end## < stop_condition)) {
ptr = ptr->next;
}
}
// instance of call
elem_forward_until(ptr, &ptr->s.t_end##, stop_condition);
// -------------- Attempt 2
// function
void elem_forward_until2(seg_list_elem_t ptr, int offset, int stop_condition) {
while (ptr && ((ptr + offset) < stop_condition)) {
ptr = ptr->next;
}
}
// instance of call
elem_forward_until2(ptr, offsetof(struct seg_list_elem_t), stop_condition);
Regards,
Wes