函数出现莫名其妙的递归现象 貌似ret地址被修改

ttlyfast 2007-11-01 05:17:46
这函数哪出毛病了怎么出现递归现象了哪?
(跟踪中...)
貌似ret地址被什么更改了 ...


#include <stdio.h >
#include "stdarg.h"

void (*error1)(const char *format, ...)
__attribute__((noreturn))
__attribute__((format(printf, 1, 2)));

void simple_va_fun(const char *format,...) ;
void caller1();
int main()
{
caller1();
}

void caller1()
{
error1 = &simple_va_fun;
error1("n=%d,%d,%d,%d,%d,\n", 4,5,4,7,3,8,2,9,100);
}

void simple_va_fun(const char *format,...)
{
va_list arg_ptr;
int nArgValue =3;
int nArgCout=0;
va_start(arg_ptr,format);
do
{
++nArgCout;
printf("the %d th arg: %d",nArgCout,nArgValue);
nArgValue = va_arg(arg_ptr,int);
}while(nArgValue != 100);
return;
}


...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ttlyfast 2007-11-02
  • 打赏
  • 举报
回复
哎...
  高手懒的做
  新手不太会做

  自问自答8

看到了没:
  编译器没给 caller1
  生成ret 语句
  所以 
  call 4010e0 <_simple_va_fun>
  过了以后就跑到main里面去拉


00401050 <_caller1>:
401050: 55 push %ebp
401051: b8 64 00 00 00 mov $0x64,%eax
401056: 89 e5 mov %esp,%ebp
401058: 83 ec 28 sub $0x28,%esp
40105b: ba e0 10 40 00 mov $0x4010e0,%edx
401060: b9 04 00 00 00 mov $0x4,%ecx
401065: 89 44 24 24 mov %eax,0x24(%esp)
401069: b8 09 00 00 00 mov $0x9,%eax
40106e: 89 44 24 20 mov %eax,0x20(%esp)
401072: b8 02 00 00 00 mov $0x2,%eax
401077: 89 44 24 1c mov %eax,0x1c(%esp)
40107b: b8 08 00 00 00 mov $0x8,%eax
401080: 89 44 24 18 mov %eax,0x18(%esp)
401084: b8 03 00 00 00 mov $0x3,%eax
401089: 89 44 24 14 mov %eax,0x14(%esp)
40108d: b8 07 00 00 00 mov $0x7,%eax
401092: 89 15 20 30 40 00 mov %edx,0x403020
401098: ba 05 00 00 00 mov $0x5,%edx
40109d: 89 44 24 10 mov %eax,0x10(%esp)
4010a1: b8 04 00 00 00 mov $0x4,%eax
4010a6: 89 4c 24 0c mov %ecx,0xc(%esp)
4010aa: 89 54 24 08 mov %edx,0x8(%esp)
4010ae: 89 44 24 04 mov %eax,0x4(%esp)
4010b2: c7 04 24 00 20 40 00 movl $0x402000,(%esp)
4010b9: e8 22 00 00 00 call 4010e0 <_simple_va_fun>
4010be: 66 90 xchg %ax,%ax

004010c0 <_main>:
4010c0: 55 push %ebp
4010c1: b8 10 00 00 00 mov $0x10,%eax
4010c6: 89 e5 mov %esp,%ebp
4010c8: 83 ec 08 sub $0x8,%esp
4010cb: 83 e4 f0 and $0xfffffff0,%esp
4010ce: e8 5d 00 00 00 call 401130 <___chkstk>
4010d3: e8 e8 00 00 00 call 4011c0 <___main>
4010d8: e8 73 ff ff ff call 401050 <_caller1>
4010dd: c9 leave
4010de: c3 ret
4010df: 90 nop


  编译器凭啥不给俺生成ret?
  查资料发现
  __attribute__((noreturn))
  就是不让编译器生成ret(原来可以这样用哦 嘿嘿)

参考:
  http://ocliteracy.com/techtips/gnu-c-attributes.html#noreturn
  
ttlyfast 2007-11-02
  • 打赏
  • 举报
回复
firnwolf 那小子
我刚贴出答案就给结贴了 郁闷
请问大牛, 在函数里面如何获取函数的返回值地址啊. [无满意答案结贴]
http://topic.csdn.net/u/20071101/18/219b7a7b-a034-4fbe-a10c-1daf477a3c57.html

我这个小三角级别在论坛上转了好几天刚得5分
55555
飞哥 2007-11-01
  • 打赏
  • 举报
回复
无能为力了,我没有c编译器
ttlyfast 2007-11-01
  • 打赏
  • 举报
回复
看了一天程序
脑袋都大挖!
自己顶个先 

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧