Linkage Specification C and C++ Recapitulation

Linkage Specification C and C++ Recapitulation
Every overloaded function is changed by the C++ compiler in such a way that it is uniquely identified at run-time and there is no overhead to find the correct version at run-time.

When a function name is changed by the compiler for unique identification at run-time, the process is known as name decoration or name mangling.

Linking happens after compilation. Inline functions are processed by the compiler, whereas non-inline functions are processed at run-time.

• C++ functions are similar to C functions. The functions,
such as calling, returning, and executing, work in the
same manner and the stack is involved in the same way
as in C.
• C++ provides an inline function. This function call
is expanded like a macro. Inline functions are very
efficient and solve the problems associated with the
macros of C. However, it is not possible to make all
functions inline.
• It is possible for the arguments to have a default value in
C++. The default arguments, if any, must be preceded
by all the normal arguments in the argument list.
• Functions in C++ can receive as arguments and return
objects additionally.
• It is possible to pass a reference and return a reference
from a C++ function.
• When a C++ function returns a reference, it can be
on the RHS of an assignment statement. Function
prototype is compulsory in C++ when the function is
used before the definition.
• It is also possible to overload a function with the same
name but different numbers of arguments or different
types of arguments in C++. This is known as function
overloading.
• A C++ function can be defined as a member function of
some class or a non-member function.
• It requires critical introspection to decide whether to make a function a member or a non-member.
• It is also possible to declare a function as a friend of
some class. In such a case, the function that is not the
member of the specific class will be able to access the
private members of the class.
• Like const and volatile variables, we can have const
and volatile objects in C++. A function can also be a
const or a volatile function.
• A const function cannot alter the value of a data member
except for the ones defined as mutable.
• Functions can also be defined as static. These functions
are not exactly member functions of a class. They
can only work with static data members of the class.
Usually, these functions are public.
• A pointer to a non-member function is similar to a
function pointer in C. It is also possible to defi ne a
function pointer to a function member in C++. They are
very useful in making the program more flexible.
• It is possible for a C++ program to use a compiled C
function from some library. We need to have a C linkage
specification for such functions.
• A normal C function in its compiled form is different
from a C++ function because the C++ function is name
mangled whereas a C function is not. Thus, a function
when compiled as a C function generates a different object
code than when the same function is compiled as a C++
function.

*

Post a Comment (0)
Previous Post Next Post