473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

int i=5; p=(++i)*(++i)*(++i);should p always be 392?

392 means 7*7*8
Can't it be 8*8*8 or any other?
I wonder whether the calculation sequence in such an expression is
specified in ansi c.
Thanks in advance.
Nov 13 '05 #1
3 1580
Liu Jin <bl*****@sohu.com> wrote:
392 means 7*7*8
Can't it be 8*8*8 or any other?
I wonder whether the calculation sequence in such an expression is
specified in ansi c.
Thanks in advance.


It is not defined, and this code invokes so called undefined behavior
which means that anything may happen, from nuclear weapon attack at your
desk or nasal daemons to program runs as expected by silly programmer.

You must not modify an object more than once inbetween to sequence
points.

Please read the faq: http://www.eskimo.com/%7Escs/C-faq/s3.html

--
Z (Zo**********@daimlerchrysler.com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
Nov 13 '05 #2

On Wed, 9 Jul 2003, Liu Jin wrote:

392 means 7*7*8
That's one way of putting it, although (1) that assumes you're
writing in base 10; and (2) the factorization 2^3*7^2 is a much more
traditional way of representing 7*7*8.
Can't it be 8*8*8 or any other?
8*8*8 is 2^9, or 512 base 10. That's not 392 in any base.
Sorry. (Unless you're using a different meaning for *
than multiplication, of course.) It's just the way that
Western mathematical notation works.
I wonder whether the calculation sequence in such an expression is
specified in ansi c.
What sort of expression? 7*7*8? In that case, it really doesn't matter
which operation is done first. (ISO C does specify that most operations
of the same precedence take place from left to right, though.)
Thanks in advance.


Try sci.math for questions about prime factorization.

-Arthur

Nov 13 '05 #3
bd
On Wed, 09 Jul 2003 02:46:51 -0700, Liu Jin wrote:
Subject: int i=5; p=(++i)*(++i)*(++i);should p always be 392?
392 means 7*7*8
Can't it be 8*8*8 or any other?
I wonder whether the calculation sequence in such an expression is
specified in ansi c.


Nothing is specified about the (poorly) indicated expression - your
compiler can do whatever it likes with it, which is not restricted to
merely modifying i and p. In theory, it could make demons fly out of your
nose.
--
Freenet distribution not available
The rule is, jam to-morrow and jam yesterday, but never jam today.
-- Lewis Carroll

Nov 13 '05 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Andy Visniewski | last post by:
Should be easy, but I've been trying to figure this out for about half an hour with no luck. There is a table 'Cybex' which has all the Cybex products we sell, and a table 'Datasheets' which...
19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
4
by: RC | last post by:
I just got my first Access project that I am getting paid for. I have done other Access work for non-profits that I did not get paid for. I definitely have the work but we did not settle the...
47
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
61
by: norb1 | last post by:
After tracking down a bug in my Fortran program, I found that it assumed max(NaN,0.) = 0. This makes no sense, as the outcome of the operation is undefined and should be NaN. max(NaN,0.) = NaN...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
23
by: LayneMitch via WebmasterKB.com | last post by:
Hello. It's me again with another question that should generate a lot of responses. As mentioned before, I'm working on my first site (hopefully I'll be done soon and can move on to other...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.