-2

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?

Rakesh
  • 133
  • 1
  • 8

1 Answers1

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • 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 ? – Rakesh Mar 13 '18 at 11:15