0% found this document useful (0 votes)
2 views2 pages

Functions in C Language Transcript

Uploaded by

Talha Javed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Functions in C Language Transcript

Uploaded by

Talha Javed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

© Cadence Design Systems, Inc. Do not distribute.

CourseTitle :C++ Language Fundamentals v24.03


VideoTitle :functions_in_C_language
Time(HH:MM:SS) : 00:00:00

You can include the inline function specifier as a hint to the compiler to inline function calls.

Time(HH:MM:SS) : 00:00:06

The compiler may or may not inline some or all calls to the function.

Time(HH:MM:SS) : 00:00:10

You can include the static storage class specifier to provide internal linkage for a file scope function declaration, or
the extern storage class specifier to provide external linkage for any function declaration.

Time(HH:MM:SS) : 00:00:22

You must specify a type for the function declaration.

Time(HH:MM:SS) : 00:00:26

The type can be any built in or user defined type, except it cannot be an array or function type.

Time(HH:MM:SS) : 00:00:32

You can instead return a pointer to the first array element or a pointer to a function.

Time(HH:MM:SS) : 00:00:36

Definition.

Time(HH:MM:SS) : 00:00:38

It is common to pass and return a pointer to a large structure, instead of copying the structure into and out of the
function call.

Time(HH:MM:SS) : 00:00:45

If returning a pointer to a const object, then the return type must be pointer to const type.

Time(HH:MM:SS) : 00:00:52

You can also return a pointer to const type to prevent the use of the pointer to modify the pointed to object.

Time(HH:MM:SS) : 00:00:58

You can omit the parameter list or alternatively explicitly specify a void parameter list.

Time(HH:MM:SS) : 00:01:05

The parameter list otherwise is a list of declarations.

Time(HH:MM:SS) : 00:01:09

You can omit the parameter identifier if declaring a type rather than defining a function.

Time(HH:MM:SS) : 00:01:14

The standard also describes a variable argument list.

Time(HH:MM:SS) : 00:01:17

This training does not address this example.

Time(HH:MM:SS) : 00:01:21
© Cadence Design Systems, Inc. Do not distribute.
First passes and returns a large structure by value.

Time(HH:MM:SS) : 00:01:24

Passing values into and out of function calls is safe because all modifications are to the copied value.

Time(HH:MM:SS) : 00:01:31

However, for large objects, the attendant performance degradation is typically unnecessary.

Time(HH:MM:SS) : 00:01:37

Here, the entire structure is copied into and out of the function call, but the function modifies only a very small
piece of it.

Time(HH:MM:SS) : 00:01:45

In the example, we see that struct one containing two integer arrays of 100 elements, each is passed into the
function pass underscore value, where it modifies only one element of an array struct two.

Time(HH:MM:SS) : 00:01:57

Copying this struct into the function causes much overhead.

Time(HH:MM:SS) : 00:02:01

The changes are made on the local copy struct two.

Time(HH:MM:SS) : 00:02:05

This doesn't affect the value of struct one.

Time(HH:MM:SS) : 00:02:08

The example next passes and returns a large structure by pointer.

Time(HH:MM:SS) : 00:02:12

Passing non-const pointers into and out of function calls preserves performance, but shares objects between calls
so it may inadvertently clobber a shared object.

Time(HH:MM:SS) : 00:02:22

Here we see when we change the value of struct underscore p value of struct one changes to the struct
underscore p value and vice versa as both pointers point to same memory location.

Time(HH:MM:SS) : 00:02:35

The example lastly passes and returns constant structure pointers.

Time(HH:MM:SS) : 00:02:40

It is good programming practice to declare passed pointers constant wherever possible, even if they point to
non-constant objects to prevent inadvertent modification of the pointed to object.

Time(HH:MM:SS) : 00:02:51

Here, the compiler detects the attempt to modify the structure through a pointer to constant type.

Time(HH:MM:SS) : 00:02:57

In the example, we see the function parameter, which is a pointer to struct underscore t is declared constant,
hence it's illegal to modify its contents.

Time(HH:MM:SS) : 00:03:08

We see that the contents of struct one and c struct p are the same.

You might also like