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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:24:26+00:00 2026-05-11T01:24:26+00:00

Calling all C macro gurus… Is there any way to write a C macro

  • 0

Calling all C macro gurus…

Is there any way to write a C macro that will replace something like this:

my_var = 5; 

with this:

setVar(&my_var, 5); 

In other words, can I write a C macro that will override assignments for a specific variable (in the above example, my_var) and instead pass it to a function whose job it is to set that variable? If possible, I’d like to be able to hook into assignments of a specific variable.


EDIT: After thinking about this some more, I’m not sure it could be done. Even if you can come up with a macro to do it, setVar wouldn’t necessarily know the type of the variable its setting, so what would be the type of its second argument?


EDIT: The reason I’d like to hook assignments of specific variables is for use in a primitive debugger for some specialized embedded C code. It would be nice to be able to have a ‘watch list’, essentially like you have in an IDE. My first instinct was to try to hook variable assignments with a C macro so you could just drop the macro into your code and have that variable ‘watched’, but then again I’ve never really written a debugger before so maybe I’m going about that all wrong.

  • 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. 2026-05-11T01:24:26+00:00Added an answer on May 11, 2026 at 1:24 am

    Not with the standard preprocessor. It cannot change the parsing of the file, only replace proper names with a piece of code (and ‘=’ isn’t valid in a name).

    If you’re feeling adventurous, you can try to replace the executable ‘cpp’ with a small script which pre-processes the source code. But that might wreck havoc with the debugging information (file name and, if you’re replacing one line of code with several, with line number information, too). The script would call ‘sed’`:

    sed -e 's/my_var\s*=\s*([^;]+);/MY_VAR(my_var, $1);/' file.c > file_tmp.c 

    But your best bet is probably to put this into a script and simply run it on all your sources. This will change the code and you’ll see what is happening in your debugger.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Xenu is the best link checker tool I have found.… May 12, 2026 at 7:13 pm
  • Editorial Team
    Editorial Team added an answer You want if re.search('[A-Za-z0-9]+', i): print i May 12, 2026 at 7:13 pm
  • Editorial Team
    Editorial Team added an answer Worked around this by creating a custom dictionary that logs… May 12, 2026 at 7:13 pm

Related Questions

Calling all C macro gurus... Is there any way to write a C macro
Some background: As a personal project, I've been developing a kernel in c++. Things
I am developping on Windows with DevStudio, in C/C++ unmanaged. I want to allocate
I'm trying to change TCP/UDP of a virtual machine using VBoxManage setextradata. Whenever I
This is a follow up to one of my previous questions and I have

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.