M
mathog
C has a very small number of unary operators that change the value of
the variable they operate on. (What is the technical name for unary
operators that do this?) These are:
i++, ++i, i--, --i
Most unary operators in C do not change the value of the variable, like:
result = 1 + -var;
if(!var){
Anyway, does anybody know historically why they went with ++ for
increment instead of using a more general and extensible form like
<variable><unary indicator><operator> postfix form
<operator><unary indicator><variable> prefix form
where if "@" had indicated unary operators of this type, then "postfix
increment" would have been:
i@+
???
This came up in the context of a discussion on C99 bool, where the
expected "in place" unary operator "!!" is not available because
!!var
already has a meaning in C (and one that does not change the value of
var), leaving no space for an "in place" unary variant that would have
negated the value of var. Had the language employed an extensible form
then when C99 came along with the bool type it would have been simple to
add:
!@var;
equivalent to
var != var;
Thanks,
David Mathog
the variable they operate on. (What is the technical name for unary
operators that do this?) These are:
i++, ++i, i--, --i
Most unary operators in C do not change the value of the variable, like:
result = 1 + -var;
if(!var){
Anyway, does anybody know historically why they went with ++ for
increment instead of using a more general and extensible form like
<variable><unary indicator><operator> postfix form
<operator><unary indicator><variable> prefix form
where if "@" had indicated unary operators of this type, then "postfix
increment" would have been:
i@+
???
This came up in the context of a discussion on C99 bool, where the
expected "in place" unary operator "!!" is not available because
!!var
already has a meaning in C (and one that does not change the value of
var), leaving no space for an "in place" unary variant that would have
negated the value of var. Had the language employed an extensible form
then when C99 came along with the bool type it would have been simple to
add:
!@var;
equivalent to
var != var;
Thanks,
David Mathog