Re: question about printf
From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 05/26/04
- Next message: Richard Bos: "Re: development in C for a cgi program"
- Previous message: Richard Bos: "Re: question about printf"
- Maybe in reply to: pratik: "question about printf"
- Next in thread: Dan Pop: "Re: question about printf"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 May 2004 12:26:51 GMT
Case <no@no.no> wrote:
> Richard Bos wrote:
> > "Vijay Kumar R Zanvar" <vijoeyz@globaledgesoft.com> wrote:
> >
> >>"pratik" <pratikthakkar007@yahoo.com> wrote in message
> >>
> >>> printf("%d%d%d",a++,++a,a);
> >> This program can said to be unportable. The reason is that the order
> >>of evaluation of arguments is unspecified. The above program, upon compilation,
> >>gives the following warning messages.
> >
> > No, no, and no. It is not merely unportable; it is downright incorrect.
> > The reason is not merely that argument evaluation order is unspecified,
> > but that a is modified twice, and read one extra time, between adjacent
> > sequence points, causing undefined, not just unspecified, behaviour. And
> > it may give these messages on _your_ system, but that is far from
> > guaranteed.
>
> Which two sequence points do you mean? I've read the FAQ about this
> issue and if I understand it right, there are no sequence points in
> a function argument list.
Exactly. The previous sequence point is just after the previous
statement (or in this case, declaration); the next sequence point is
just before printf() is called. Those are the two adjacent sequence
points I meant; between them, a is modified twice and read three times,
of which once not for the reason of computing the modified value.
Richard
- Next message: Richard Bos: "Re: development in C for a cgi program"
- Previous message: Richard Bos: "Re: question about printf"
- Maybe in reply to: pratik: "question about printf"
- Next in thread: Dan Pop: "Re: question about printf"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|