Thursday, May 12, 2005

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.

2 Comments:

At 10:26 PM, Anonymous Anonymous said...

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

 
At 10:46 PM, Blogger Unknown said...

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.

 

Post a Comment

<< Home