Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between pointer functions and function pointers in arm

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about the difference between pointer functions and function pointers in arm. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In the process of learning arm, it is found that the "pointer function" and "function pointer" are easy to make mistakes. The easiest way to distinguish is to see if the pointer * sign in front of the function name is contained in parentheses (). If it is included, it is a function pointer, otherwise it is a pointer function.

First of all, the definition between them:

1. A pointer function refers to a function with a pointer, that is, it is essentially a function, and the function return type is a pointer of a certain type.

Type identifier * function name (parameter table)

Int * f (XBI y)

First of all, it is a function, but the return value of this function is an address value. The function return value must be accepted with a pointer variable of the same type, that is, the pointer function must have a function return value, and, in the main tone function, the function return value must be assigned to the pointer variable of the same type.

Indicates:

Float * fun ()

Float * p

P = fun (a)

Let's be more specific. Please look at the following

Pay attention to the difference between the pointer function and the function pointer representation, do not confuse.

Pointer function:

When a function declares its return value as a pointer, it actually returns an address to the calling function for use in expressions that require a pointer or address.

Format:

Type specifier * function name (parameter)

Of course, since an address is returned, the type specifier is usually int.

For example:

Int * GetDate ()

Int * aaa (int,int)

Function returns an address value, which is often used on the address of an element in the returned array.

Copy the code

1 int * GetDate (int wk,int dy)

2 main ()

3 {

4 int wk,dy

5 do {

6 printf (Enter week (1-5) day (1-7)\ n)

7 scanf (% d% d retro wkjigdy)

8}

9 while (wk5 | | dy7)

10 printf (% d\ nGetDate (wk,dy))

11}

twelve

13 int * GetDate (int wk,int dy)

14 {

15 static int calendar [5] [7] =

16 {

17 {1,2,3,4,5,6,7}

18 {8,9,10,11,12,13,14}

19 {15,16,17,18,19,20,21}

20 {22,23,24,25,26,27,28}

21 {29pyrum 30pcr 31pyrmus 1}

22}

23 return & Germanar [wk-1] [dy-1]

24}

Copy the code

The program should be easy to understand, and the subfunction returns the address of an element in the array. The output is the value in this address.

2. A function pointer is a pointer variable pointing to a function, that is, it is essentially a pointer variable.

Int (* f) (int x); / * declare a function pointer * /

Assign the first address of the func function to the pointer f * /

The pointer to the function contains the entry address of the address of the function, through which the function can be called. The format of the declaration is as follows:

Type specifier (* function name) (parameter)

In fact, it can not be called the function name, but should be called the variable name of the pointer. This special pointer points to a function that returns an integer value. The declaration stroke of the pointer is consistent with its declaration to the function.

The parentheses outside the pointer name and pointer operator change the default operator priority. Without parentheses, it becomes a prototype declaration of a function that returns an integer pointer.

For example:

Void (* fptr) ()

You can assign the address of a function to a function pointer in the following two forms:

Fptr=&Function

Fptr=Function

Taking the address operator is not necessary because a function identifier alone is labeled to represent its address and, in the case of a function call, must also include a table of parameters enclosed in parentheses.

You can call a function through a pointer in two ways:

X = (* fptr) ()

X=fptr ()

The second format looks like a function call. But some programmers prefer the first format because it makes it clear that functions are called through pointers rather than function names.

Here is an example:

Copy the code

1 void (* funcp) ()

2 void FileFunc (), EditFunc ()

three

4 main ()

5 {

6 funcp=FileFunc

7 (* funcp) ()

8 funcp=EditFunc

9 (* funcp) ()

10}

eleven

12 void FileFunc ()

13 {

14 printf (FileFunc\ n)

15}

sixteen

17 void EditFunc ()

18 {

19 printf (EditFunc\ n)

20}

Copy the code

The program output is:

FileFunc

EditFunc

The main difference is that one is a pointer variable and the other is a function. In use, it is necessary to find out before you can use it correctly.

Thank you for reading! About "what are the differences between pointer functions and function pointers in arm?" this article ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report