459,403 Members | 1,335 Online
Need help? Post your question and get tips & solutions from a community of 459,403 IT Pros & Developers. It's quick & easy.

Question about the *= (and similar) operator

 P: n/a In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ? Jun 13 '06
56 Replies

 P: n/a pete wrote: CBFalconer wrote: pete wrote: James Dow Allen wrote: I guess we should record that as an "Aye" vote. I'm still voting "Neigh." You have a horse voice. You lose, so pony up. That would be if his voice was only a little horse. Can you write that as an e quine? -- "A man who is right every time is not likely to do very much." -- Francis Crick, co-discover of DNA "There is nothing more amazing than stupidity in action." -- Thomas Matthews Jun 17 '06 #51

 P: n/a Joe Wright wrote: .... snip ... Our realloc can be a misbehaving child and needs attention. Consider.. int *ptr; ptr = malloc(100 * sizeof *prt); ptr = realloc(ptr, 200 * sizeof *ptr); Assume malloc works and then realloc fails. We'll have ptr set to NULL and no reference to the memory malloc gave us. A leak! So you never misuse realloc in that manner. Instead: if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp; else announcememoryshortage(); no leak. -- "A man who is right every time is not likely to do very much." -- Francis Crick, co-discover of DNA "There is nothing more amazing than stupidity in action." -- Thomas Matthews Jun 17 '06 #52

 P: n/a CBFalconer writes: Joe Wright wrote: ... snip ... Our realloc can be a misbehaving child and needs attention. Consider.. int *ptr; ptr = malloc(100 * sizeof *prt); ptr = realloc(ptr, 200 * sizeof *ptr); Assume malloc works and then realloc fails. We'll have ptr set to NULL and no reference to the memory malloc gave us. A leak! So you never misuse realloc in that manner. Instead: if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp; else announcememoryshortage(); no leak. Storing the result of realloc() in a separate variable is an excellent habit. In practice, though, it may not turn out to be useful. It's possible for a program to respond to a realloc() failure by falling back to some less memory-intensive algorithm that uses the previously allocated object (similarly for malloc() failuers), but it's more likely to do some cleanup and bail out. On the other hand, you might need information in the previously allocated object to do the cleanup. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. Jun 17 '06 #53

 P: n/a CBFalconer wrote: Joe Wright wrote: ... snip ... Our realloc can be a misbehaving child and needs attention. Consider.. int *ptr; ptr = malloc(100 * sizeof *prt); ptr = realloc(ptr, 200 * sizeof *ptr); Assume malloc works and then realloc fails. We'll have ptr set to NULL and no reference to the memory malloc gave us. A leak! So you never misuse realloc in that manner. Instead: if (tmp = realloc(ptr, 200 * sizeof *ptr)) ptr = tmp; else announcememoryshortage(); no leak. Yes, of course. -- Joe Wright "Everything should be made as simple as possible, but not simpler." --- Albert Einstein --- Jun 18 '06 #54

 P: n/a CBFalconer wrote: pete wrote: CBFalconer wrote: pete wrote: James Dow Allen wrote:> I guess we should record that as an "Aye" vote.> I'm still voting "Neigh." You have a horse voice. You lose, so pony up. That would be if his voice was only a little horse. Can you write that as an e quine? You've really got the bit between your teeth now. But I fear we're getting a bit far from the mane thread. Jun 19 '06 #55

 P: n/a pete wrote: CBFalconer wrote: pete wrote: James Dow Allen wrote:> I guess we should record that as an "Aye" vote.> I'm still voting "Neigh." You have a horse voice. You lose, so pony up. That would be if his voice was only a little horse. Perhaps he has a little colt. Richard Jun 19 '06 #56

 P: n/a rl*@hoekstra-uitgeverij.nl (Richard Bos) writes: pete wrote: CBFalconer wrote: > > pete wrote: > > James Dow Allen wrote: > > > >> I guess we should record that as an "Aye" vote. > >> I'm still voting "Neigh." > > > > You have a horse voice. > > You lose, so pony up. That would be if his voice was only a little horse. Perhaps he has a little colt. That would be a filly lame excuse. -- Chris. Jun 19 '06 #57

56 Replies