-1

Is there a way that we can call user defined function when we are calling arithmetic operator in a C program just like operator overloading in C++. using GNU GCC Compiler? Simply, I have a function add(), and in my C program I have arithmetic Operation

 c = a + b;

when I compile the program, it should call my add() function internally for + operator.

and Is there a way we can see what is the code that gcc compiler is calling when it encounters + operator?

2
  • You can use the gcc -S option to compile from C to assembly language, so you can examine the code it generates. Commented Mar 13, 2018 at 11:00
  • Thank you that was helpful :-). Commented Mar 13, 2018 at 11:17

1 Answer 1

1

No.

C does not work that way, you cannot overload/override the basic built-in operators.

Seeing the code is of course possible, either by making gcc emit it directly using -S, or by disassembling the resulting binary. The related binutils tool is objdump.

These days much such exploration can also be made "online" using the fantastic Compiler Explorer tools at godbolt.org, of course.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the link :-). recently i was working with arm-buildroot-linux-uclibceabi-gcc compiler where i was able to redirect the calls of floating point operations +,-,*. Since the compiler was cross compiler similarly, wouldn't that be possible in gcc itself ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.