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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:41:59+00:00 2026-06-12T11:41:59+00:00

I intend to adjust (or gain info about) the functioning of a program without

  • 0

I intend to adjust (or gain info about) the functioning of a program without changing anything to the actual code. I originally hoped this could be done by using the C++ operator overloading functionality, but first tests are not satisfying.

Concrete

I have a simple function in sample.c file:

void dunno() {
    int x = 1;
    int y = 4;
    int z = x + y;
}

To alter the functionality I create a header file which (in my head) would looked like the following:

...

int operator+(int x1, int x2) // this syntax is obviously not allowed by C++?
{
    // Change and gain knowledge here!
    return something here;
}   


#include "sample.c"

...

With other words: I try to alter the real meaning of for example two ints that are being added. And most important when the unmodified function tries to add two ints my operator overloaded function should be called instead of the standard C int+int…

Sorry guys, it’s hard to decently explain what I intend to say.

  • 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-12T11:42:00+00:00Added an answer on June 12, 2026 at 11:42 am

    You could potentially sort of make this work by writing a value-wrapper class for each primitive you want to intercept (or making it a template on the storage type), and then using macros, like so:

    template <typename T> class Primitive;
    template <typename T>
    Primitive<T> operator+(Primitive<T>, Primitive<T>);
    
    template <typename T> class Primitive {
        T value;
    public:
        typedef Primitive<T> MyType;
        Primitive<T>(T);
        // ...    
        friend MyType operator+<T>(MyType, MyType);
        // etc. etc.
    };
    
    
    #define int Primitive<int>
    #include "sample.c"
    #undef int
    
    ...
    

    but this is going to get unimaginably hairy and you really shouldn’t do it.

    The key thing to understand is that you’d be transforming the code so much by doing this, it’s hard to be sure how much the behaviour is changed. Also, it will just break the any headers included by sample.c which declare out-of-line functions or variables.

    A better approach is probably just to step through the code in a debugger, if you really want to see exactly what it does (or, if suitable, template dunno on its data type so you can pass a debugging value type without macro hackery).

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

Sidebar

Related Questions

I intend to replace all the strings starting as style= having anything in-between and
I intend to share my source code on an invite-only basis to a few
I intend to create a java program/service that continuously polls rss-feeds using the informa
i intend to display some information when i right click on a textbox. this
I intend to write a small program to check IIS service connectivity and statistics
I intend to have a busy waiting spinner as per shown in this post:
I intend to around existing code snippet (updating a Hashtable) with lock() block to
I intend to generate JSON that's like this: { stores: [{Name:abc,Phone,1234567},{Name:def,Phone,1111111}], numResults: 2 }
I intend to use PHP_Beautifier in a code evaluation tool I'm working on but
I intend for part of a program I'm writing to automatically generate Gaussian distributions

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.