I tried to print the location of the file pointer in GDB:

*inptr printed

Unfortunately this was so information intensive it was useless. I stumbled across ftell and hard coded it into my program:

ftell current location

and it was much more ergonomic. ftell was incredibly useful for shedding light on the resize problem. Is there a way to get a pointer byte location from GDB in relation to the beginning of the file as seen in ftell?

1 Answer 1


since you've already assigned a variable to each of your pointers, you can print out their values at any time in gdb via: p in p out (p is shorthand for print)

  • I may be missing something, but it seems that the print command is only good once in this example, at the point when the variables are assigned the value through ftell. After that, as the pointer moves, there's nothing repeating in the code to update "in" and "out". Nor would you really want something so repetitive, right? How would you go about finding the current location of the pointers through GDB as you continue to move through the program? Aug 15, 2016 at 21:47
  • 1
    In the OP above, variable in=ftell(inptr) so at any point in time, it gives the position of the inpointer as it reads the instream, so it is always moving forward. What OP does is printf its current position as it reads infile, which is a bit clunky for debugging. Instead, at any point as you're stepping through your code in GDB, you can determine inptr's current position by typing p in.
    – ronga
    Aug 16, 2016 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .