Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling printf() by its pointer

Tags:

c

pointers

printf

Everything works:

#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;
}

But this does not work:

#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;
}

Whats I am doing wrong? Tell me, please. Can I call printf (or some other function) by its pointer?

like image 495
user2862654 Avatar asked Oct 24 '25 15:10

user2862654


1 Answers

In the second example, printf is not linked to your program.

like image 135
CS Pei Avatar answered Oct 26 '25 04:10

CS Pei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!