我在哪里可以找到实现++运算符? [英] Where can I find the implementation for the ++ operator?

查看:147
本文介绍了我在哪里可以找到实现++运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里可以找到C / C ++实现的 + 运营商对数字和指针?

Where can I find the C/C++ implementation of the ++ operator for numbers and pointers?

我看着各地的网络,但并没有找到太多......

I looked around the web but didn't find much...

推荐答案

可能是我的回答(对数)有益高达某种程度上:
<子>你可以驾驶答案指针

May be my answer (for number) helpful upto some extend:
you can drive answer for pointer

int main(){
    int i=0,j=0;
    j=i++;  // expresion includes two operations `+, =      
    printf("%d %d",j,i);
}

您可以使用 -S 标记与海湾合作委员会(G ++)拆解
我的code的名字叫 M.C

You can disassemble it using -S flag with gcc (g++):
My code name is m.c

$ gcc -S m.c

这将创建一个 MS 汇编文件。

阅读评论我说:

pushl   %ebp
movl    %esp, %ebp
andl    $-16, %esp
subl    $32, %esp

movl    $1, 28(%esp)            // i due to declarations 
movl    $0, 24(%esp)            // j

movl    28(%esp), %eax          // this two lines are j = i
movl    %eax, 24(%esp)

addl    $1, 28(%esp)            // increment to i, i++

movl    $.LC0, %eax
movl    28(%esp), %edx
movl    %edx, 8(%esp)
movl    24(%esp), %edx
movl    %edx, 4(%esp)
movl    %eax, (%esp)
call    printf

这是如何分配 = 先发生再 + 。如果 + 为后缀。

This how assignment = happen first then ++. If ++ is postfix.

(按照我的编译器)

抽象语法树EX pression的自下而上的评估 J = ++

Bottom-up evaluation of the abstract syntax tree for expression j = i ++.

源$ C ​​$ C:

source code:

j = i++;  

在低级别分为两个指令(你可以在组装code见):
    J =     我++

At Low level broken into two instructions (as you can see in assembly code):
j = i i++

其中,我++ I = I + 1

// abstract syntax tree

       + (post)
      / \
     /   \  
    =     1 
   / \       
  /   \
 j     i  

CASE的preFIX + (+ I):

CASE OF PREFIX ++ (++i):

也想,如果EX pression将 J = ++我然后我就直接写抽象语法树:

Also suppose if expression would be j = ++i then I directly writing abstract syntax tree:

它首先增量 + 然后 = 执行;

It will first increments ++ then = performs;

// abstract syntax tree for j = ++i  

    =
   / \       
  /   \
 j     \ 
       + (prefix)
      / \
     /   \  
    i     1 

大会$ C $下 J = ++我,其中 J = 0 I = 1 开始:

movl    $1, 28(%esp)          // i declaration 
movl    $0, 24(%esp)          // j  
addl    $1, 28(%esp)          // First  Add 1 to i because i++ (before = perform)
movl    28(%esp), %eax        // Below two steps: = performed  j = i 
movl    %eax, 24(%esp)

这篇关于我在哪里可以找到实现++运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆