通过指针调用printf()

use*_*654 3 c printf pointers

一切正常:

#include <stdio.h>

int (* func)(const char * fmt, ...);

int main()
{
  func = (void *)0x400420; /* printf pointer */
  printf("printf address: %p\n", printf);
  func("func() calling\n");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用:

#include <stdio.h>

int (* func)(const char * fmt, ...);

int main()
{
  func = (void *)0x400420; /* printf pointer */
  /* printf("printf address: %p\n", printf); */
  func("func() calling\n");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么?请告诉我.我可以用它的指针调用printf(或其他一些函数)吗?

CS *_*Pei 7

在第二个示例中,printf未链接到您的程序.