[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/language/as_if [Back]  [Original]

-- cppreference.com
cppreference.com

--

cppreference.com

, .

C++ , :

1) , volatile ( , )
( C++11)
1) ( ) volatile , . , volatile .
( C++11)
2) , , , , .
3) , , , .

() , , - volatile , . , . .

, - , , .., --: . , , if(n+1 < n) abort();, , , , , .

--: , .

new --: , .

( C++14)

, , , , :

#pragma STDC FENV_ACCESS ON
for (i = 0; i < n; ++i) x + 1; // x+1  ,    FP 
// (    ).    n  
//        .  ,    :
if (0 < n) x + 1;

int& preinc(int& n) { return ++n; }
int add(int n, int m) { return n+m; }

// volatile     
volatile int input = 7;

// volatile ,      
volatile int result;

int main()
{
    int n = input;
//      
//    int m = ++n + ++n;
//    ,    ,
// --   
    int m = add(preinc(n), preinc(n));
    result = m;
}

:

#    main(),   GCC
# x86 (Intel) :
        movl    input(%rip), %eax   # eax = input
        leal    3(%rax,%rax), %eax  # eax = 3 + eax + eax
        movl    %eax, result(%rip)  # result = eax
        xorl    %eax, %eax          # eax = 0 (  main())
        ret

# PowerPC (IBM) :
        lwz 9,LC..1(2)
        li 3,0          # r3 = 0 (  main())
        lwz 11,0(9)     # r11 = input;
        slwi 11,11,1    # r11 = r11 << 1;
        addi 0,11,3     # r0 = r11 + 3;
        stw 0,4(9)      # result = r0;
        blr

# Sparc (Sun) :
        sethi   %hi(result), %g2
        sethi   %hi(input), %g1
        mov     0, %o0                 # o0 = 0 (  main)
        ld      [%g1+%lo(input)], %g1  # g1 = input
        add     %g1, %g1, %g1          # g1 = g1 + g1
        add     %g1, 3, %g1            # g1 = 3 + g1
        st      %g1, [%g2+%lo(result)] # result = g1
        jmp     %o7+8
        nop

#      preinc()  ,
#    main()     result = 2*input + 3;

C --

Web Proxy Viewer  |  New URL  |  Original Page