Chinaunix首页 | 论坛 | 博客
  • 博客访问: 272314
  • 博文数量: 124
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 21
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-20 14:44
文章分类

全部博文(124)

文章存档

2020年(1)

2018年(2)

2016年(2)

2015年(6)

2014年(10)

2013年(23)

2012年(7)

2011年(18)

2010年(15)

2009年(8)

2007年(8)

2006年(23)

2005年(1)

我的朋友

分类: C/C++

2006-02-07 15:26:01

#include
#include
using namespace std;
typedef unsigned int DWORD;
typedef unsigned short int WORD;
typedef DWORD (*a)(int );

int mm()
{
    return -1;
}

WORD hello(int i)
{
    mm();
    return 300;
}
void main()
{
    DWORD m;
    a func;
    func=(a)hello;
    m=(*func)(10);
    cout<
}

由于调用mm()函数改写了当时的eax值,使之为-1,当hello中的return被之行时,由于返回short类型,所以ax的值被更改。使得此时是ax中保存了返回值,eax中是一个错误的值。
有由于func在赋值时被强行转化,导致在m被赋值时,得到的是eax的内容。所以m此时的值不是hello所返回的值。

以上是从vc的汇编代码中看到的,但是linux下的g++都会进行转化,m仍能够得到正确的值。
阅读(1003) | 评论(0) | 转发(1) |
1

上一篇:makefile

下一篇:tcpdump 命令使用指南

给主人留下些什么吧!~~