How an overloaded function is internally exposed during the compilation process in C ++

Possible duplicate:
In C ++, how is function overloading usually done?

I was looking at Bruce Eckel's book OOPS

, which talked about working on overloaded functions when they have a difference in return values ​​and passed arguments.


int fun() :: could be represented as __int__fun
float fun():: could be represented as __float__fun
int fun(int a):: as _int _fun_int

      

but how does overloading work in case of blocks in c

               {
                  void fun(){}
                  ...........
                  ..
                  fun()
               }
               /......sme code/
               {
                   void fun(){}
               }

      

can anyone explain how this is displayed internally?

+3


source to share


4 answers


In C, two functions with the same name in different blocks are called like this:

functionName.number

For example, you might have:

fun.2051

and



fun.2053

I figured it out by compiling the C program with the following command:

gcc -S -o test.asm test.c

Then I opened the build file and noticed that gcc was tagged with functions.

+1


source


Defining functions within blocks is not legal in C ++.

If we assume that for one short second such things are legal, your two functions are still not overloaded. They just have areas that don't overlap. Your example is no different from this:



  {
     int i;
     ...
  }
  {
     int i;
     ...
  }

      

There is no "overloaded variable" here, and there is no overloaded function in your example.

+4


source


A block can only be executed within a function. C ++ does not support / allow nested functions (i.e. one function defined inside another function), so the question never comes up.

If allowed (for example by a compiler like gcc as an extension), you still won't overload. Overloading requires two (or more) objects with the same base name to be visible within the same scope. In this case, each name will be in a separate scope, in which case no overloading will take place - you have a normal scope search that finds a name from the local scope itself that matches.

Edit: As a third party, I should add that, contrary to what you've shown, the return type of a function is probably not normally included in the overloaded / decorated overload of the name function, it depends on the "signature" function that includes the parameter types, but not return type.

0


source


how an overloaded function is internally represented during the compilation process in C ++

Google "C ++ name mangling ". It will be exposed as a normal function with a name like thiswriteCDATA@QXmlStreamWriter@@QAEXABVQString@@@Z

but how does overloading work in case of blocks

Your code example does not contain valid C ++ code and will not compile.

0


source







All Articles