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

  • Home
  • SEARCH
  • 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 858389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:32:17+00:00 2026-05-15T08:32:17+00:00

im programming embedded devices and I was wondering what to use for a macrofunction,

  • 0

im programming embedded devices and I was wondering what to use for a macrofunction, for example an init of some registers.
should i make this static/const or define it as a macro?

for example, this:

 #define FPGA_INIT()\
{ \
  /* Set function and direction of start_code pin*/\
  P0SEL &= ~0x04; \
  P0DIR |= 0x04; \
  FPGA_START_CODE = 0; \
}

or this?

static void fpga_init()
{ 
  /* Set function and direction of start_code pin*/
  P0SEL &= ~0x04; 
  P0DIR |= 0x04; 
  FPGA_START_CODE = 0; 
}

And what’s the difference in memory-placement?

  • 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-15T08:32:18+00:00Added an answer on May 15, 2026 at 8:32 am

    In general, it is best to reserve the use of preprocessor macros for times when you need the capability of the preprocessor to manipulate the code before it is compiled—you should not use preprocessor macros to define procedures that can be implemented as normal functions. Because the preprocessor substitutes the macro code wherever the macro is invoked, it can be difficult to debug errors that occur. For example, if you call your FPGA_INIT() macro, the (presumably) global variables P0SEL, P0DIR, and FPGA_START_CODE might be hidden by locals of the same name.

    If you declare a fpga_init() function, the compiler will place the code for that function along with the code for other functions you declare, according to whatever rules it knows for the platform you are targeting. If you declare a FPGA_INIT() macro, the compiler will never know it exists, as all references to it will be resolved by the preprocessor; the compiler will see and compile the macro’s statements separately within each function it was invoked.

    Unless you need to call this code with great frequency (in an inner loop), the performance of the macro and function implementations will likely be indistinguishable. If you do need to call the code frequently, you should try measure the performance each way: depending on the architecture of your processor, it may be faster to use the preprocessor to place the code inline, or it may be faster to have the code in a separate function (particularly if expanding every invocation causes an important loop to overflow a cache line).

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

Sidebar

Related Questions

In traditional embedded programming, we will give a delay function like so: for(i=0;i<255;i++) for(j=0;j<255;j++);
I'm looking to learn about embedded programming (in C mainly, but I hope to
Does anyone know any good online embedded software programming with C or assembler resources?
I'm programming in C for RAM limited embedded microcontroller with RTOS. I regularly break
Programming languages had several (r)evolutionary steps in their history. Some people argue that model-driven
Some programming languages such as Java and C# include encryption packages in their standard
I am new to Embedded Programming, taking courses on it. And working with ATSTK600.
I'm very new to embedded programming, and my first project is installing uCos on
I am a hobbyist programming for an embedded application. The application requires speed. I
Programming Student here...trying to work on a project but I'm stuck. The project is

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.