Increment file pointer

B

bd

Irrwahn said:
No, one byte beyond it. Look:

FILE *p;

|current FILE object|
|sizeof(FILE) bytes |
+-+-+-+-+-+-+~~~~-+-+-+-+~~~~~~
^ ^
p before ... and after increment.

Regards

Ah, I read it as one byte beyond the *start* of the current FILE object...
 
B

Barry Schwarz

Ah, I read it as one byte beyond the *start* of the current FILE object...
No, it is one byte beyond the ***end*** of the current FILE object.
Unless sizeof(FILE) is 1, these are not the same.

Consider an array of FILE objects and a FILE*.

FILE files[5];
FILE *ptr;
ptrdiff_t diff;
ptr = files;

ptr obviously points to files[0].

ptr++;

Just as obviously, ptr now points to files[1]. Like all arrays, the
five elements of files are consecutive in memory with no overlap and
no gaps.

diff = ptr-files;

Disregarding any type differences, the value in diff is guaranteed to
be equal to sizeof(FILE)


<<Remove the del for email>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top