c - How can I make a user provide its own function in my library? -


i writing static library avr mcu. using avr-gcc , avr libc. of library functions use spi communicate device. however, spi communication not done same way on avr mcus (not of them have same registers concerned). can done big-banging. thus, want user provide own spi routine, specific application.

how can this? should library functions take callback function additional argument? should have global variable within library acting spi handler? should make function external (using extern)?

thank you,

the simple , straightforward solution declare appropriately named extern function. lets compile library without extern function yet existing. neither or users able link complete executable without providing appropriate function.

i've used approach myself , recommend it. avoids unnecessary complications, uses nothing isn't absolutely fundamental c programming environments, , importantly obvious errors flagged @ build time not @ run time (you won't runtime crashes undefined callback functions called).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -