WEBVTT

00:01.090 --> 00:07.540
When you call a function, the compiler will create a stack frame for the new function call and it will

00:07.540 --> 00:10.090
push items onto the stack here.

00:10.090 --> 00:19.480
So the data itself, the data put on the stack depends on your compiler, the whether the code is compiled

00:19.480 --> 00:22.060
for the debug or the release build here.

00:22.060 --> 00:30.490
So however, in general the there will be information about the parameters passed here, the information

00:30.490 --> 00:37.690
pass parameters and to the function, the return address here and the address, the name of the function

00:37.690 --> 00:42.100
call here and the automatic variables are located in this function here.

00:42.100 --> 00:47.440
This means that the when you make a function call at a runtime, there will be a memory overhead and

00:47.440 --> 00:53.770
performance overhead from creating the stack frame before the function runs and the performance overhead

00:53.800 --> 00:57.640
in when you clean this function up.

00:57.640 --> 00:59.590
So after the function completes here.

00:59.590 --> 01:06.230
So if a function is inline, this overhead does not occur because the function call will use the current

01:06.230 --> 01:08.180
stack frame rather than a new one.

01:08.180 --> 01:15.320
So clearly the inline function should be small, both in terms of code and the memory used on the stack

01:15.320 --> 01:24.410
here, so the compiler can ignore the inline specifier and call the function with a separate stack frame.

01:24.410 --> 01:29.450
So we can actually specify the call conventions in this cplusplus here.

01:29.480 --> 01:37.310
So when your code uses your own functions, you do not need to pay any attention to calling conventions

01:37.310 --> 01:42.140
because the compiler will make sure that the appropriate convention is used.

01:42.140 --> 01:49.970
So however, if you are writing library code that can be used by other cplusplus compilers or even by

01:49.970 --> 01:53.780
other languages, the calling convention becomes important.

01:53.780 --> 01:59.480
So since this course is not about interoperable code, we won't go into much depth here.

01:59.480 --> 02:05.930
But instead we will look at two aspects function naming and stack maintenance.

02:06.600 --> 02:09.390
So we can also use the C linkage here.

02:09.660 --> 02:15.840
So when you give a C plus plus function a name, this is the name that you will use to call the function

02:15.840 --> 02:18.060
in your C plus plus code.

02:18.090 --> 02:24.810
However, under the covers, the C plus plus compiler will decorate the name with the extra symbols

02:24.810 --> 02:31.890
for the return type and the parameter so that the overloaded functions all have different names.

02:31.890 --> 02:34.730
So to the C plus plus developers.

02:34.740 --> 02:41.430
This is also known as the name mangling mangling.

02:41.430 --> 02:48.060
So if you need to export a function through the shared library, for example, in Windows Dynamic Link

02:48.090 --> 02:54.150
library, this means that that dll files for the.

02:56.590 --> 03:04.570
Shared library library in windows here that dll files here.

03:04.570 --> 03:07.420
So this means dynamic link library.

03:07.420 --> 03:12.010
So you must use the types and names that the other languages can use.

03:12.010 --> 03:19.690
So to do this you can mark a function with the extension C here, this means that function has C linkage

03:19.690 --> 03:28.480
and the compiler will not use the external code and you should not use it with the function that have

03:28.480 --> 03:37.360
return values and parameters that use the C plus plus custom types extern C here like that.

03:37.360 --> 03:38.500
So.

03:39.790 --> 03:46.660
However, if such function does return a cplusplus type, the compiler will only use a warning.

03:46.690 --> 03:54.850
The reason is that the C is a flexible language and the C programmer will able to work out how to turn

03:54.850 --> 03:57.850
the Cplusplus type into something usable.

03:57.850 --> 04:01.890
But it's poor practice to abuse them like this here.
