[comp.lang.c] Terminology

mitch@manta.NOSC.MIL (Ray Mitchell) (04/15/91)

Here's a question to reflect my misunderstanding of some basic terminology.
Upon looking for a concise, English definition of the term "expression" in
a multitiude of C texts, the best I can come up with is:

	"Any combination of constants, variables, and operators
	 (producing a value)"

I put "producing a value" in parentheses because therein lies my problem.  It
seems intuitively clear that an expression must have a value and it follows
that a function returning a value qualifies as an expression.  However, how
about a function returning "void" or an expression cast to type "void"?  Are
these two cases no longer considered to be expressions or is "void" considered
to be a value for the sake of the definition of an expression?

Ray Mitchell

gwyn@smoke.brl.mil (Doug Gwyn) (04/16/91)

In article <1917@manta.NOSC.MIL> mitch@manta.NOSC.MIL (Ray Mitchell) writes:
>Upon looking for a concise, English definition of the term "expression" in
>a multitiude of C texts, the best I can come up with is:
>	"Any combination of constants, variables, and operators
>	 (producing a value)"

The precise definition of "expression" would be any production derivable
from the grammar rules, starting with the nonterminal "expression".  For
maximum utility one should also stipulate that the production violates
no constraints.

In other words, don't try to short-cut the carefully worked-out standard
for the language; the standard is as elaborate as it is because that is
what it takes to accurately specify the C language.

dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) (04/16/91)

In <1917@manta.NOSC.MIL> mitch@manta.NOSC.MIL (Ray Mitchell) tries
to define an "expression":

    "Any combination of constants, variables, and operators (producing
     a value)"

     It seems intuitively clear that an expression must have a
     value...  However, how about a function returning "void" or an
     expression cast to type "void"?

In colloquial technical English, an expression is any entity that has a
value.  Therefore a function returning "void" is not an expression.
The purpose of introducing such functions into C was to belatedly add
procedures to the language.  Languages that have procedures don't need
void-returning functions.

But when you define a programming language, the concept of "expression"
as described above is not necessary.  Languages that use the term
"expression" use it only as a syntactic token to which some meaning
must be separately assigned.  Instead of saying "expression" you can
say "gadget" or "whatist" without losing any information.  So, if the
grammar of a language (e.g. C) allows an "expression" to be, among
other things, a function returning void, it's purely for notational
convenience.

In other words, "expression" means whatever you want it to mean.  A
function returning void is not an expression--unless you say so.
--
Rahul Dhesi <dhesi@cirrus.COM>
UUCP:  oliveb!cirrusl!dhesi