'Programing/Language'에 해당되는 글 2건

  1. 2016.12.05 [C++] About inline
  2. 2016.11.30 Why learn C language.
2016. 12. 5. 13:57

----------------------------------------------------------------------

Hello, i am GameDeveloperPlayground.

I am a Korean student and I post it for English practise.

I would appreciate pointing out grammar or typos.

----------------------------------------------------------------------


In this post I will post about inline, one of the reserved words in C++


This is one of the reserved words that comes out when you look at c++ books.


To put it plainly, inline functions are where the coded of the complied function is inserted directly into the program's code.



Shall see the code?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
 
using namespace std;
 
inline void Inlinefuction()
{
    cout<<"*** Inlinefuction() ***"<<endl;
}
 
 
int main()
{
 
    Inlinefuction();
 
    return 0;
}
cs


When you compile the code.


1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
 
using namespace std;
 
int main()
{
 
    cout<<"*** Inlinefuction() ***"<<endl;
 
    return 0;
}
cs


It will changed as above. How about this?


Let's check with assembly code to see more results.


First, if you look at the main function of assembly code that is not inline.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
; 12   : {
 
    push    ebp
    mov    ebp, esp
 
; 13   :     Inlinefuction();
 
    call    ?Inlinefuction@@YAXXZ            ; Inlinefuction
 
; 14   :     return 0;
 
    xor    eax, eax
 
; 15   : }
 
    cmp    ebp, esp
    call    __RTC_CheckEsp
    pop    ebp
    ret    0
cs


Will come out as above.


Inline apply assembly code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
; 12   : {
 
    push    ebp
    mov    ebp, esp
    push    esi
 
; 13   :     Inlinefuction();
 
    mov    esi, esp
    mov    eax, DWORD PTR __imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z
    push    eax
    push    OFFSET ??_C@_0BI@FMEKNHNP@?$CK?$CK?$CK?5Inlinefuction?$CI?$CJ?5?$CK?$CK?$CK?$AA@
    mov    ecx, DWORD PTR __imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A
    push    ecx
    call    ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char> >
    add    esp, 8
    mov    ecx, eax
    call    DWORD PTR __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z
    cmp    esi, esp
    call    __RTC_CheckEsp
 
; 14   :     return 0;
 
    xor    eax, eax
 
; 15   : }
 
    pop    esi
    cmp    ebp, esp
    call    __RTC_CheckEsp
    pop    ebp
    ret    0
cs


Come out like this.


Look at line 13, can see the difference.


Let's change the function more easily.



Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
 
using namespace std;
 
int Inlinefuction(int a, int b)
{
    return a+b;
}
 
 
int main()
{
    int n;
    n = Inlinefuction(1,2);
    return 0;
}
cs


Assembly code not use Inline.

1
2
3
4
5
6
7
8
9
10
11
12
; 13   :     int n;
; 14   :     n = Inlinefuction(1,2);
 
    push    2
    push    1
    call    ?Inlinefuction@@YAHHH@Z            ; Inlinefuction
    add    esp, 8
    mov    DWORD PTR _n$[ebp], eax
 
; 15   :     return 0;
 
    xor    eax, eax
cs


Assembly code use Inline.

1
2
3
4
5
6
7
8
9
10
; 13   :     int n;
; 14   :     n = Inlinefuction(1,2);
 
    mov    eax, 1
    add    eax, 2
    mov    DWORD PTR _n$[ebp], eax
 
; 15   :     return 0;
 
    xor    eax, eax
cs


Look at code 14, can feel the difference.


No call on the assembly code.

And push is not being called either.




Looking at the process of calling a generic function, first the stack is push parameters, and the function is called.


Then there are push and pop stack for the return value in the function. After return, there is pop for stack cleanup.


Because these function calls access the stack, they can slow down, because accessed by memory.


When use inline, the first thing is speed and memory effect.


Disadvantage is that if use it repeatedly, the assembly code becomes longer.


If the function is called multiple times and written in assemblycode.. is not that a joke?



Conclusion.


Well, my conclusion from my brief knowledge.

Function that has a short syntax and fewer calls is use inline.


I would appreciate it if you point out in a comment field. please.


Thankyou.






'Programing > Language' 카테고리의 다른 글

Why learn C language.  (0) 2016.11.30
Posted by 시리시안
2016. 11. 30. 16:47

----------------------------------------------------------------------

Hello, i am GameDeveloperPlayground.

I am a Korean student and I post it for English practise.

I would appreciate pointing out grammar or typos.

----------------------------------------------------------------------

Original Links : http://silisian.tistory.com/30



Why we have to study C language?


First. Each university first teaches C language.

why?

C language is the basis for all programming languages.


So, why is C the basis of all programming languages?

Many other programming languages are written in C or C language models.


So, why are many other programming languages written in C or C language models?

Let's look at history.



History at C language.


The reason is, of course, C language was used by a many programmers.


The reason why C language is loved so much is C language has merits.


C language was defines the basic things.


Also, Additional extensions are possible if the definition does not deviate.


So, C language has a lot of similar versions, there are so many different languages that can be called C languages.


American National Standards Institue( ANSI ) define ANSI C.


C lanuage which was created in this way, grew like a living life.


Every time new programming techniques and theories arise put it in C language. 

If the disadvantage of C language is found, have modified the structure of the language. 


C language is so very powerful and very messy programming language. :<

Because C language has beening revised since the year 1971.



C language is intermediate language.


Machinge language in the programming language  that can be understood by the machine, which is a combination of numbers 0, 1.


Assembly is a language that make it a little bit meaningful by matching it an English word.


Here are the low-level languages.


So, high-level language is that makes the instruction more meaningful from apart low level language.


C language is clearly high level language.



Origin of language names


Origin of C language name.

Once upon a time there was language called 'B language'. The language created by the motif is 'C language'.


Origin of C++ language name.

Once upon a time C language plus 'Class' called 'C with class', which is too long to be called 'C++'.


Origin of C# language name.

Once upon a time there was a language called 'C++', plus add one more '++' 

C++

  ++

Like C#. :>


C language projections


The C language is not used more often.

The reason id that it takes too long to create programs.


It's good for hardware control, but performance is getting lower because it's not as productive.


Comprehensive summary


C is good.

C has strong performance.

Many programming languages are written in C or C in motif.

However, the dfficiency of work is low.(To type a lot of batter) But is fast!!

C is so long many Programs are written is C.

To study them.


C must be! :>


thank you.





'Programing > Language' 카테고리의 다른 글

[C++] About inline  (0) 2016.12.05
Posted by 시리시안