This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: question about printf
- To: Kent B Mein <mein at cs dot umn dot edu>
- Subject: Re: question about printf
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 19 Nov 1998 09:03:48 +0000
- CC: egcs-bugs at cygnus dot com
- Organization: Computer Science Dept, Bristol University
- References: <199811181807.SAA09779@jessica.cs.umn.edu>
Kent B Mein wrote:
>
> I have a kind of goofy question,
> Not sure if this is the place to talk about it or not.
> I scanned through the old posts and couldn't find anything about it.
>
> Basically here is the problem (Which occurs only on linux machines)
>
> printf("%c %c %c %c\n",getchar(),getchar(),getchar(),getchar());
>
> Preforms the getchar's backwards. Is this a problem, or is it just
> a coding problem?
C (and C++) do not define the order in which function parameters are
evaluated (they may be in any order including intermixed)[1]. if getchar
is a macro and performs sideffects, you have invoked undefined effects.
see http://www.eskimo.com/~scs/C-faq/q3.2.html for more details.
> The fix is of course to store the getchar's in var's before
> printing them out.
yes.
nathan
[1] if they are functions, C++ does not allow the function evaluation to
be intermixed.
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk