Operator should be += OR =+

We are quite used to operators like +=, -=.

Just going through the history of C, I came to know that older versions of C used =+, =- to mean what the operators +=,-= mean these days. And they changed it when they realized that assignment of a -ve number to integer is rather ambiguous e.g.

int i;
i =-1 // i is supposed to be -1 but this was resolved as i=i-1;

A way round to this problem might have been something like this

int i = 0;
i =- 1;

Of course it will not work in cases when i contains anyvalue other than zero.

Advertisements

2 Responses to Operator should be += OR =+

  1. Anonymous says:

    Well
    i=-1; // In this case the readibilty is decreased bcz it is at first sight thought to be -1 so keeping in view of the language aspects the case should be:

    i-=1; / which is the better case of readibiltiy and easy to understand

  2. Mian Fahim says:

    Yeah You are right. Readibility is decreased as well and still it was not possible to assign -1 to an integer without first assigning 0 to it when this syntax is used.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: