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 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

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you by any chance compiling in debug mode? It… May 15, 2026 at 7:47 pm
  • Editorial Team
    Editorial Team added an answer NSURL *videoURL = [NSURL URLWithString:@"http://..."]; [webView loadRequest:[NSURLRequest requestWithURL:videoURL]]; UPDATE: In… May 15, 2026 at 7:47 pm
  • Editorial Team
    Editorial Team added an answer While apply can certainly be used for this, funcall might… May 15, 2026 at 7:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.