Question

I have a question about changing parameter name of a member function.

I have function foo(type iA) then I change to foo(type iB), I think it is bin comp, but I am not sure.

Could you help me to explain the reason? Thanks a lot!

Was it helpful?

Solution

Of course it will be binary compatible because you do not change the type of object. Hence the size stays the same. Name of variable is only for human.

You can actually declare function not giving any names, like:

int funct(void*, int, Object)

When you define it you can use whatever you like

int funct(void* ptr, int something , Object object){return 42;};

It is fine. It also works for class members.

The (I would say main) reason for binary compatibility or incompatibility are the sizes of passed objects. So when you operate on actual binary data, on assembler level no offsets change. If you changed types, arguments would lie in different places in memory, and offsets for them would need to be recalculated. What is important are addresses not aliases or names.

Edits:

For the sake of the completeness. As @Lightness pointed out, you can also skip names in definition, so the very example I gave could look: int funct(void*, int, Object){return 42;};.

Also regarding @James' comment. I would say that when two objects have the same size, it gets murky. Of course it makes no sense to make such wild conversion from one type to another. However, considering previous example, if you do not use operand it would probably work ... on the assembler level. If sizes differed it would corrupt stack.

However, when I thought how to comment on this problem, I told myself that you ask about c++. So let's look at it from this point of view. I would say that functions are binary compatible when their signature does not change. And names of operands are not part of it in any definition. Function signature is a basis for name mangling and overloading, and the symbol name in the final binary object.

OTHER TIPS

The names of the arguments is just for you to distinguish the arguments. You can have different names in a function declaration and the functions definition.

So this is okay:

void foo(int bar);  // Declare function

...

// Define function
void foo(int bibibibibi)
{
    ...
}

The declaration and definition above is for the same function. C++ does not override or overload functions based on argument names, only argument types.

The compiler does not store the names of arguments (or other variable) except as debug info. The actual generated code have no information about the variable names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top