Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!kth!sunic!sics.se!uplog!uplog.uplog.se!thomas From: thomas@uplog.se (Thomas Hameenaho) Newsgroups: comp.lang.c Subject: Re: printf() problem Message-ID: Date: 27 Apr 89 14:04:52 GMT References: <11657@hodge.UUCP> Sender: thomas@uplog.UUCP Organization: TeleLOGIC Uppsala AB Lines: 26 In-reply-to: jdm@hodge.UUCP's message of 26 Apr 89 00:25:48 GMT In article <11657@hodge.UUCP> jdm@hodge.UUCP (jdm) writes: Perhaps someone could explain this printf() phenomena to me. I have a file with binary data. I want to read four consecutive bytes from the file and display them with printf(). The data in in the file in hex is: 92 AB 4E 33 I fopen() the file in binary mode and used the following line of code to read and print out the data: printf("%x %x %x %x\n", getc(fp), getc(fp), getc(fp), getc(fp)); printf() displays it as: 33 4E AB 92 The problem is that the evaluation order of the arguments to printf (in this case) is not defined in C. One should NOT have expressions with sideeffects in function calls. The code will be inherently non-portable. -- Real life: Thomas Hameenaho Email: thomas@uplog.{se,uucp} Snail mail: TeleLOGIC Uppsala AB Phone: +46 18 189406 Box 1218 Fax: +46 18 132039 S - 751 42 Uppsala, Sweden