我如何找到函数的确切地址 [英] How I Find The Exact Address Of Function Puts

查看:117
本文介绍了我如何找到函数的确切地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<string.h>
int main()
{
char str[100]={0};
char str1[100]={0};
char *p = NULL;
puts("enter a string");
fgets(str,sizeof(str),stdin);
puts("enter substring");
fgets(str1,sizeof(str1),stdin);
p=strstr(str,str1);
if(p)
puts("sub string is a part of main string");
if(!p)
puts("sub string is  not a part of main string");
return 0;
}





我知道我可以使用p& str,p& str1获取变量str,str1的地址分别。但是如何让gdb显示puts()的地址?



I know I can get the address of variables str,str1 using p &str, p &str1 respectively. But how can I get gdb to show me the address of the puts()?

推荐答案

你可以使用

You can use
#include <stdio.h>

//...

int (_cdecl * fpointer)(const char*) = &puts;
// where int (_cdecl * fpointer)(const char*) declares the variable "fpointer"
// of the type "pointer to the function accepting one argument of the type "const ''char*"
// and returning int"

// or even

void* address = &puts;





但是为什么?



请参阅: http://www.cprogramming.com/tutorial/function -pointers.html [ ^ ] 。



-SA


这篇关于我如何找到函数的确切地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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