473,837 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about the *= (and similar) operator

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 4830
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
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 announcememorys hortage();

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
CBFalconer <cb********@yah oo.com> 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 announcememorys hortage();

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_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 17 '06 #53
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 announcememorys hortage();

no leak.

Yes, of course.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jun 18 '06 #54
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
pete <pf*****@mindsp ring.com> 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
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
pete <pf*****@mindsp ring.com> 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

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

Similar topics

7
3695
by: Jessica | last post by:
Hi, I have a design question. I am making a time series analysis tool. Since I already use STL vector to represent time series, is there a need to implement a class for the time series object? Right now I just use typedef vector<double>TS; Is that enough? I feel that I am not taking advantage of the C++
3
4974
by: Stephan Kurpjuweit | last post by:
Hi, could you please help me with the following example? struct Base { virtual Base& operator = (const Base &k) {} };
8
1382
by: Derek Long | last post by:
I believe that the following is valid c++: #include <iostream> template <typename CMP> class Comparator { bool operator()(int x,int y) { return CMP(x,y);
105
5375
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does not work. It only works on lists and strings, for no obvious reason. Why not on all sequence types? Or, another example, the index() method has start and end parameters for lists and strings. The count() method also has start and end parameters...
18
1550
by: Xiaoshen Li | last post by:
Dear All, I have a question regarding to linking separate files for compilation. For example, I have two file in the same directory: file1.cpp & file2.cpp. ==> file1.cpp <== int iNumber= 999; ==> file2.cpp <== #include <iostream>
10
1489
by: Jeroen | last post by:
Hi guys, Just another question. Suppose I have 2 classes (incomplete code): class A { A(const B& b); A& operator = (const A& a); }; class B {
16
6093
by: Juha Nieminen | last post by:
I'm actually not sure about this one: Does the standard guarantee that if there's at least one element in the data container, then "--container.end()" will work and give an iterator to the last element in the container? Or is there a cleaner way of getting an iterator to the last element?
8
4407
by: JackC | last post by:
Hi, I am trying to get posix threads working from within an object, heres some code: int NConnection::TheadControl() { int thread_id; pthread_t new_connection; pthread_create(&new_connection, NULL, PriC, (void *)thread_id);
3
2963
by: Michel Esber | last post by:
Hi all, Db2 v8 FP15 LUW . create table T (ID varchar (24), ABC timestamp) There is an index for (ID, ABC), allowing reverse Scans. My application needs to determine MIN and MAX(ABC) for a given ID. We are currently using a simple statement:
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10870
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10621
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10267
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5668
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4038
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.