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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:52:56+00:00 2026-06-11T14:52:56+00:00

Is it possible to define a macro in a C file, and then change

  • 0

Is it possible to define a macro in a C file, and then change behavior of another C file using this definition?

For instance, suppose we have a file named b.c:

#include <stdio.h>
#define ABC

void function() {
    printf("b.c\n");
}

And another file named a.c:

#include <stdio.h>

int main() {
    #ifdef ABC
        printf("b.c defined this\n");
    #endif
    printf("a.c\n");
}

These files are compiled together. I want the definition of ABC in b.c to influence a.c.

I know I was supposed to be using a header file, but I don’t want to do that. Is there another way to achieve this?

In my scenario, b.c is a sort of sub-application that will complement the behavior of a.c, and it should also be able to override behavior in there.

Is there an alternative to macros that can achieve this?

  • 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-06-11T14:52:57+00:00Added an answer on June 11, 2026 at 2:52 pm

    Use global variables or use callbacks. The “best” solution depends on precisely how much flexibility you need.

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

Sidebar

Related Questions

In object type macro it is possible below, #define str this is a string
Is it possible to concatenate string from another macro when #including a file name
Is it possible to define a macro in my Spring application context XML file
I have this macro code, which allows me to define both a C enum
I have a macro like this: #define SHOW_EXPR(x) printf (%s=%d\n, #x, (x)) It works:
I currently have this macro #define bind(OBJECT, ROLE) \ assert( sizeof(*ROLE) == 1 );
Is is possible to define a macro BREF(...): struct bits { int b0:1; int
With gcc (and possibly other compilers as well) it's possible to define a macro
Possible Duplicates: What’s the use of do while(0) when we define a macro? Why
Is it possible to have scoped macros using custom defined macros through boost wave?

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.