Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   1995

Need explanation about some things in C++

by Pshyotic - 16 July, 2018 - 03:05 PM
This post is by a banned member (Pshyotic) - Unhide
Pshyotic  
Registered
1.013
Posts
290
Threads
6 Years of service
#1
Hello everbody, I first want to say that I couldn't find the corresponding section of the forum to post and ask things about programming, so I hope here will be okay and I think that this forum should have section for this purpose.
So, I really don't get mean of inline function in C++ ,  .. Here is one of the codes for this:
Code:
1:   // Listing 5.9 - demonstrates inline functions
2:
3:   #include <iostream.h>
4:
5:   inline int Double(int);
6:
7:   int main()
8:   {
9:     int target;
10:
11:    cout << "Enter a number to work with: ";
12:    cin >> target;
13:    cout << "\n";
14:
15:    target = Double(target);
16:    cout << "Target: " << target << endl;
17:
18:    target = Double(target);
19:    cout << "Target: " << target << endl;
20:
21:
22:    target = Double(target);
23:    cout << "Target: " << target << endl;
24:       return 0;
25:  }
26:
27:  int Double(int target)
28:  {
29:    return 2*target;
30: }


I do not understand the purpose of using the inline function, even if some function is not declared inline function, the compiler will perform the same as the code where the inline function is, respectively, both will do the same.


And after this question, I have question about recursion, I get it how storage works and purpose of recursion, but if anyone have some code and explanation of that code is not too complicated I would like to write to me here or in messages. 

Thanks :)
 
P S H Y O T I C

☻♥
[Image: Czwhvkg.png]
This post is by a banned member (Yuki) - Unhide
Yuki  
Contributor
159
Posts
52
Threads
6 Years of service
#2
(This post was last modified: 16 July, 2018 - 03:26 PM by Yuki.)
To avoid function call overhead you use inline function and for recursion , it's good if you use it in dynamic programming using array or some que stack or linked list ro store data of previously performed steps else your programme will end up at being at some infinite recursion point and wont be able to figure out where it started and because of that you will get a stack over flow error , ooof

I'll hit you up with sample code when I reach home
This post is by a banned member (Pshyotic) - Unhide
Pshyotic  
Registered
1.013
Posts
290
Threads
6 Years of service
#3
(16 July, 2018 - 03:24 PM)Wylin Wrote: Show More
To avoid function call overhead you use inline function and for recursion , it's good if you use it in dynamic programming using array or some que stack or linked list ro store data of previously performed steps else your programme will end up at being at some infinite recursion point and wont be able to figure out where it started and because of that you will get a stack over flow error , ooof

I'll hit you up with sample code when I reach home

Okay, I think I'll wait for example code, but what I get is this that inline function and recursion is good for dynamic programming... And hell so I think that the rest of my life will be reduced to dynamic programming, since it comes down to what is known as "divide and rule", yet there are many functions, classes and objects ...
 
P S H Y O T I C

☻♥
[Image: Czwhvkg.png]
This post is by a banned member (xxxs) - Unhide
This post is by a banned member (Pshyotic) - Unhide
Pshyotic  
Registered
1.013
Posts
290
Threads
6 Years of service
#5
(19 July, 2018 - 05:41 PM)xxxs Wrote: Show More
The CPU requires some time to fetch the instruction then transfer the control for each instruction in the process. And for some function, if the execution time is smaller than the time required for the processor to switch controls over to the function then the efficiency of the code with respect to time decreases a bit so for those kinds of functions inline is used.

Heh... You are a Little bit late but , because I found explanation of it...  But thank you, anyways for your time...
 
P S H Y O T I C

☻♥
[Image: Czwhvkg.png]
This post is by a banned member (ictos) - Unhide
This post is by a banned member (Edward) - Unhide
Edward  
Registered
344
Posts
162
Threads
#7
Sadly I don't work with cpp.
[Image: DARKHOST_2.gif]

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)