C ++指针访问类似集会 [英] C++ Pointer access similar to assembly

查看:95
本文介绍了C ++指针访问类似集会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我看到C ++不同的数组访问的风格,并认为这可能是相对于组装寻址方式:

Sometimes i see different array-access styles in C++ and thought it could be relative to an assembly addressing mode:

C ++

int * aa=new int[2];
0[aa]=15; //a little different than aa[0]
1[aa]=15;
aa[0]=15;
aa[1]=15;
printf("%d %d \n",aa[0],aa[1]);

大会:

__asm
{
    mov aa[0],ebx
    mov aa[1],eax
    mov 0[aa],ebx
    mov 1[aa],eax
}

这是C ++数组访问符号标准,如果是,它是从装配寻址模式派生?

当我尝试 [AA] 1 = 5; ,编译器给


  • AA属性未找到,

  • 缺少;之前'常量'

  • 左操作数必须是左值。

  • "aa attribute not found",
  • "missing ';' before 'constant'"
  • "left operand must be l-value".

//当我尝试指针运算,

//When i try pointer arithmetic,

*(AA + 1)= 0 //没有给出误差

*(aa+1)=0//gives no error

*(AA + 0)= 0 //没有给出错误:)

*(aa+0)=0//gives no error :)

这是规则同为运营商[]重载?

MSVC ++ 2010

MSVC++ 2010

感谢您。

推荐答案

这是C和C的知名怪癖++,他们并不真正关心它的前pression的一半云在方括号 [] 。他们都计算为同一相当于前pression:

This is a well-known quirk of C and C++, they don't really care which half of an expression goes in the square brackets []. They both evaluate to the same equivalent expression:

*(0+aa)=15;

这篇关于C ++指针访问类似集会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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