Richard said:
In effect, ordinary C operators are functions in disguise, i.e.
functions with special syntax. Their arguments are the values of
expressions; [...]
This is true only of a subset of C's operators.
Obvious exceptions are the -> and . operators, whose
right-hand operands are not values at all. Also, I
think you'll find it difficult to write functions that
are equivalent to ++ and -- (in either position), to =
and += and their brethren, to (short) and (unsigned char)
and such, to ?:, and to ().
Where that () is funccall not grouping. Plus && || .
You're right about it only being true of a subset - that's why I
used the word "ordinary". Still, your point is well taken; C
I usually use 'computational' for this distinction.
does have operators that don't take values. The term "operator"
is a bit misleading. This is not to say that it doesn't have a
well defined meaning in the C standard; merely that the usage in
the C standard is idiosyncratic. If we use function in the
broader context of computer science and mathematics rather than
the specific meaning of a C source function I would classify
-> and . as term formation symbols,
See below.
casts as ordinary functions, and
You can treat a particular cast as a monadic value->value function,
but then you have an unboundedly extensible set of operators. To treat
cast syntax as a single operator you need a typevalued operand.
=, +=, etc as ordinary functions.
Assignment forms can be treated as functions with a caveat, the
As math function only if you include lvalues in values, which
'ordinary'<G> math i.e. arithmetic doesn't*; and as C function only if
you convert to pointers (or use C++ references). C's rough peers
(Fortran, PL/I, COBOL) do not allow assignment as a subexpression, and
F90 allows assignment to be overloaded for a userdefined (struct-like)
type as a (nonvalued and visibly nonpure) SUBROUTINE, not a valued
FUNCTION. (* Math in its full glory can manipulate almost anything the
mind can conceive, but with terminology far more bizarre and confusing
than the C standard. For example, part of modern computer cryptography
uses 'elliptic curves' which are neither elliptic nor curves.)
Those peers treat function call (where available), field selection,
and subscripting as (forms of) primaries rather than (sub)expressions
using an operator. PL/I has sort of the opposite problem: it used
named syntax for some things that 'ought' to be operators, partly
because of the 48-char BCDIC/card charset it had to support. For
example ABS(-3) is a 'built-in function' and so is SUBSTR(str,1,2)
_when used in an rvalue context_ but when the latter is used in an
lvalue context it is a 'pseudovariable'.
issue being the C sequence point business. Pre and post
decrement and increment operators go even further into that murky
territory.
AFAICS inc/dec don't cause any 'further' problem than += et al,
they're just (much) more frequent in common/idiomatic C.
- formerly david.thompson1 || achar(64) || worldnet.att.net