Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

c - void* for multiple types

Is the following considered bad practice in C?

void (* print_function) (void *obj);

Item1 *item1 = & (Item1) {.id=123};
print_function = print_item1;
print_function(item1);

Item2 *item2 = & (Item1) {.guid="X1-283"};
print_function = print_item2;
print_function(item2);

That is, trying to pass different objects multiple places by using void *? If so, why?

question from:https://stackoverflow.com/questions/65621433/void-for-multiple-types

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...