473,836 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Increment file pointer

hi folks

I have a pointer to a file. If i increment the pointer, where will it point.
I could not find the problem in the FAQs.

Thanks in advance
Deepak garg
Nov 13 '05
21 14951
Dan Pop wrote:
In <bm**********@s unnews.cern.ch> I wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc.h elsinki.fi> writes:
deepak <de*********@re diffmail.com> scribbled the following:
hi folks

I have a pointer to a file. If i increment the pointer, where will it
point. I could not find the problem in the FAQs.

It's undefined.


It's perfectly well defined: one byte after the current FILE object.
The operation is perfectly OK, as long as you don't try to dereference
the result (or pass it to some function expecting a valid FILE pointer).

The following code has well defined behaviour:


Especially after applying the following patch ;-)
FILE *mystdout == stdin;


s/stdin/stdout


....and the following following patch...

s/==/=/

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #11
Richard Heathfield <do******@addre ss.co.uk.invali d> scribbled the following:
Dan Pop wrote:
In <bm**********@s unnews.cern.ch> I wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc. helsinki.fi> writes:
deepak <de*********@re diffmail.com> scribbled the following:
> hi folks

> I have a pointer to a file. If i increment the pointer, where will it
> point. I could not find the problem in the FAQs.

It's undefined.

It's perfectly well defined: one byte after the current FILE object.
The operation is perfectly OK, as long as you don't try to dereference
the result (or pass it to some function expecting a valid FILE pointer).

The following code has well defined behaviour:
Especially after applying the following patch ;-)
FILE *mystdout == stdin;


s/stdin/stdout

...and the following following patch... s/==/=/


Dang, Dan Pop made a mistake in *two* consecutive posts and I missed the
opportunity to gloat over it. =)

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola
Nov 13 '05 #12
Joona I Palaste wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> scribbled the
following:
Dan Pop wrote:
In <bm**********@s unnews.cern.ch> I wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc .helsinki.fi> writes:
>deepak <de*********@re diffmail.com> scribbled the following:
>> hi folks
>
>> I have a pointer to a file. If i increment the pointer, where will it
>> point. I could not find the problem in the FAQs.
>
>It's undefined.

It's perfectly well defined: one byte after the current FILE object.
The operation is perfectly OK, as long as you don't try to dereference
the result (or pass it to some function expecting a valid FILE pointer).

The following code has well defined behaviour:

Especially after applying the following patch ;-)

FILE *mystdout == stdin;

s/stdin/stdout

...and the following following patch...

s/==/=/


Dang, Dan Pop made a mistake in *two* consecutive posts and I missed the
opportunity to gloat over it. =)


The Curse of Google Groups...

"many (most) programmers prefer to be _very_ careful when they type the
equality operator rather than compromise the readability of their code,
especially for the people who will have to maintain it later." - Dan Pop, 1
May 1995

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #13
Micah Cowan wrote:
Christian Bau <ch***********@ cbau.freeserve. co.uk> writes:
In article <bm**********@o ravannahka.hels inki.fi>,
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:
> Christian Bau <ch***********@ cbau.freeserve. co.uk> scribbled the
> following:
> > In article <7c************ **************@ posting.google. com>,
> > de*********@red iffmail.com (deepak) wrote:
> >> hi folks
> >>
> >> I have a pointer to a file. If i increment the pointer, where will
> >> it point.
> >> I could not find the problem in the FAQs.
>
> > Past the end of the file.
>
> Sorry, no. It might not even point at a valid FILE object at all.

It might not point to a valid "file" (whatever that is, concluding that
he meant a FILE object is pure guessing), but it definitely points past
the end of the file that the original pointer pointed to.


To be slightly more accurate, it will point past the end of the
FILE object.


I think Christian's point is that the OP never mentioned FILE, only "file".
C is case-sensitive. If that /is/ Christian's point, I think he's being a
touch over-pedantic (which is no bad thing in clc).

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #14
In <3F*********@ea rthlink.net> Joe Wright <jo********@ear thlink.net> writes:
Dan Pop wrote:

In <bm**********@s unnews.cern.ch> I wrote:
>In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
>
>>deepak <de*********@re diffmail.com> scribbled the following:
>>> hi folks
>>
>>> I have a pointer to a file. If i increment the pointer, where will it point.
>>> I could not find the problem in the FAQs.
>>
>>It's undefined.
>
>It's perfectly well defined: one byte after the current FILE object.
>The operation is perfectly OK, as long as you don't try to dereference
>the result (or pass it to some function expecting a valid FILE pointer).
>
>The following code has well defined behaviour:


Especially after applying the following patch ;-)
> FILE *mystdout == stdin;


s/stdin/stdout
> mystdout++;
> fprintf(--mystdout, "hello world\n");

I'd thought you'd have changed '==' to '=' as well.


Looks like a good idea, and it makes the compiler happy, too ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #15
In <bm**********@t itan.btinternet .com> Richard Heathfield <do******@addre ss.co.uk.invali d> writes:
Joona I Palaste wrote:
Richard Heathfield <do******@addre ss.co.uk.invali d> scribbled the
following:
Dan Pop wrote:
In <bm**********@s unnews.cern.ch> I wrote:
>In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
><pa*****@c c.helsinki.fi> writes:
>>deepak <de*********@re diffmail.com> scribbled the following:
>>> hi folks
>>
>>> I have a pointer to a file. If i increment the pointer, where will it
>>> point. I could not find the problem in the FAQs.
>>
>>It's undefined.
>
>It's perfectly well defined: one byte after the current FILE object.
>The operation is perfectly OK, as long as you don't try to dereference
>the result (or pass it to some function expecting a valid FILE pointer).
>
>The following code has well defined behaviour:

Especially after applying the following patch ;-)

> FILE *mystdout == stdin;

s/stdin/stdout

...and the following following patch...

s/==/=/


Dang, Dan Pop made a mistake in *two* consecutive posts and I missed the
opportunity to gloat over it. =)


The Curse of Google Groups...

"many (most) programmers prefer to be _very_ careful when they type the
equality operator rather than compromise the readability of their code,
especially for the people who will have to maintain it later." - Dan Pop, 1
May 1995


Except when they know that the compiler *must* catch their mistakes ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #16
bd
Dan Pop wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc.hel sinki.fi> writes:
deepak <de*********@re diffmail.com> scribbled the following:
hi folks

I have a pointer to a file. If i increment the pointer, where will it
point. I could not find the problem in the FAQs.


It's undefined.


It's perfectly well defined: one byte after the current FILE object.


Do you mean sizeof(FILE) bytes beyond it?

Nov 13 '05 #17
bd <bd*****@users. sf.net> wrote:
Dan Pop wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc.hel sinki.fi> writes:
deepak <de*********@re diffmail.com> scribbled the following:
hi folks

I have a pointer to a file. If i increment the pointer, where will it
point. I could not find the problem in the FAQs.

It's undefined.


It's perfectly well defined: one byte after the current FILE object.


Do you mean sizeof(FILE) bytes beyond it?


No, one byte beyond it. Look:

FILE *p;

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

Regards
--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #18
bd wrote:
Dan Pop wrote:
In <bm**********@o ravannahka.hels inki.fi> Joona I Palaste
<pa*****@cc.hel sinki.fi> writes:
deepak <de*********@re diffmail.com> scribbled the following:
hi folks

I have a pointer to a file. If i increment the pointer, where will it
point. I could not find the problem in the FAQs.

It's undefined.


It's perfectly well defined: one byte after the current FILE object.


Do you mean sizeof(FILE) bytes beyond it?


sizeof(FILE) bytes after the beginning of the object, or one byte
after the last byte of the object.

Jeremy.
Nov 13 '05 #19
Richard Heathfield <do******@addre ss.co.uk.invali d> writes:
Micah Cowan wrote:
Christian Bau <ch***********@ cbau.freeserve. co.uk> writes:
In article <bm**********@o ravannahka.hels inki.fi>,
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote:

> Christian Bau <ch***********@ cbau.freeserve. co.uk> scribbled the
> following:
> > In article <7c************ **************@ posting.google. com>,
> > de*********@red iffmail.com (deepak) wrote:
> >> hi folks
> >>
> >> I have a pointer to a file. If i increment the pointer, where will
> >> it point.
> >> I could not find the problem in the FAQs.
>
> > Past the end of the file.
>
> Sorry, no. It might not even point at a valid FILE object at all.
It might not point to a valid "file" (whatever that is, concluding that
he meant a FILE object is pure guessing), but it definitely points past
the end of the file that the original pointer pointed to.


To be slightly more accurate, it will point past the end of the
FILE object.


I think Christian's point is that the OP never mentioned FILE, only "file".
C is case-sensitive. If that /is/ Christian's point, I think he's being a
touch over-pedantic (which is no bad thing in clc).


Er, yeah. Clearly a case of not reading too thoroughly before
posting...

-Micah
Nov 13 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2796
by: csomberg | last post by:
SQL 2000 I thought I would throw this out there for some feedback from others. I'd like to know if you feel using MS auto-increment field is a good solution these days or should one grow their own ? Thanks, Me.
16
17282
by: Burne C | last post by:
I have something confused in my mind void *search_address = 0; ++search_address; /* The compiler complain that "void *" is unknown size. OK, I changed the code
1
2837
by: pooja | last post by:
Hi I m pooja.I m working on a prj in C. I m unable to increment a char pointer in a file, it gives the same address as that of the first char.Eg if # is on loc 3000 then i,n ,c ,l,u,d,e are on same address.Can any one plz help .
13
6388
by: kailasam | last post by:
Hello, Iam having a doubt. Which is more efficient post increment or Pre increment? I have read that preincrement is efficient than Post increment. Iam not able to think how it is? For an independent statement i++ and ++i which is more efficient? Regards Kailasam
15
2690
by: ranjeet.gupta | last post by:
Dear All, Which is correct ? Let suppose we allocate the memory for the 100 bytes, int *PtrMemoryBlock = (int *)malloc(100); If I do
7
2557
by: alex | last post by:
BlankThis maybe a known issue, but I stepped on it just now. Basically it boils down to: in C# int x = 0; Console.Write("{0}", x++ + x++); gives 1, when in C/C++ int x = 0; printf("%d\n", x++ + x++);
14
2038
by: Robben | last post by:
Hi All, I have an integer pointer with value 10, but it returns a different return value after the preincrement and post increment. I will be very thankful if somebody can give an explanation for this behavior. Listed below is the program and output - executed in vc++6.
5
13302
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that will increment/decrement the form field value by 1 when clicked. I'm using the following code, however when I click on one of the links, I get the following error -
2
2290
by: braton | last post by:
Hello I'm wondering about the following thing: Let's define variable and set a pointer to points to it: int a = 0; int * p_a = &a; Now, according to C99, clause 6.5.6.7 I can treat pointer to "a"
0
10843
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10589
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4015
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.