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 7004751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:14:21+00:00 2026-05-27T21:14:21+00:00

Normaly if I make a small code snipet, I usually put it in a

  • 0

Normaly if I make a small code snipet, I usually put it in a whathever.c – file. From the C-file I include a .h -file with other includes or some global varaibles.

I’ve just heard that the compiler makes the code in a header faster, or somtehing I would love if someone could explain or comment this.

Example code in a header instead of a c-file (could be in a c) ->

#define PWM_INTERRUPT \
void InterruptHook(void) \
{ \
    PR4 ^= _SoftPWM_Toggle; \
    \
    PIR3bits.TMR4IF = 0; \
    \
    _asm \
        INCF PR4,0,ACCESS \
        CPFSLT TMR4,ACCESS \
    _endasm \
    \
    /* if(TMR4 > PR4) */ \
        PIR3bits.TMR4IF = 1; \
    \
    SOFT_PWM_PIN ^= 1; \
    \
    _asm \
        RETFIE 1 \
    _endasm \
}
  • 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-27T21:14:22+00:00Added an answer on May 27, 2026 at 9:14 pm

    You can’t put a macro in a separate .c file, because macros are handled by the preprocessor, which is the first step in the compilation process, and separate .c files are handled in the link stage, which is the last step.

    Using a macro instead of a function might be faster, because it avoids the overhead of a function call. However, it will slow your compiles down because it compiles the same code multiple times. It will make your code larger because of redundant copies. If caching is an issue, it might actually run slower because of repeatedly fetching different redundant copies into cache. There’s no way to know for sure without profiling.

    If you’re talking about the difference between putting a macro in the same .c file and a header file, there’s no difference performance-wise. You just would have to copy and paste it into every .c file that uses it.

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

Sidebar

Related Questions

I need some code to download a pdf file. what i mean is normaly
I normally make multiple small edits to my source code, but I don't want
Normaly i would do a delete * from XXX but on this table thats
I have acustom sharepoint page. on my machine I can debug the code normaly
I'm trying to make a small VBScript that compacts a MS Access 2007 database
Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial
I made a small change to an old java file in IntelliJ and when
I have a small C program to calculate hashes (for hash tables). The code
We have some code that must access low level windows XP os calls which
I would like to hear opinions on small amounts of code replication within methods

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.