Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3935746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:51:56+00:00 2026-05-19T23:51:56+00:00

I am writing a static library for an AVR MCU. I am using avr-gcc

  • 0

I am writing a static library for an AVR MCU. I am using avr-gcc and AVR Libc. Some of the library functions use SPI to communicate with a device. However, SPI communication is not done the same way on all AVR MCUs (not all of them have the same registers concerned). It can even be done by big-banging. Thus, I want the user to provide its own SPI routine, for its specific application.

How can I do this? Should all the library functions take a callback function as an additional argument? Should I have a global variable within the library acting as an SPI handler? Should I make the function external (using extern)?

Thank you,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:51:57+00:00Added an answer on May 19, 2026 at 11:51 pm

    The simple and straightforward solution is to just declare an appropriately named extern function. This lets you compile your library without the extern function yet existing. But neither you or your users will be able to link a complete executable without providing an appropriate function.

    I’ve used this approach myself and recommend it. It avoids unnecessary complications, uses nothing that isn’t absolutely fundamental to all C programming environments, and importantly obvious errors will be flagged at build time not at run time (you won’t get runtime crashes as undefined callback functions are called).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple static library for myself recently. It include some ui control,
I'm writing a little static library (lib.a) for the iphone and I'm using ASIHTTPRequest
I'm writing a C++ static library that needs to be shared among several applications,
I'm writing my Servlet application and would like to use the following static method
I am writing a class library(API) in C#. The class is non-static and contains
I am writing a library. The library can be used by applications that use
I want to write a (static) library for other programmers to use that uses
When writing a header library (like Boost ), can one define free-floating (non-method) functions
I'm writing a proof-of-concept app to connect to LinkedIn using the scribe OAuth library.
I'm writing a library class to encapsulate some of my logic in my first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.