0

In the context of (constant) expressions: what is the difference between "with value" and "evaluate to value"?

Here are some quotes from C11 (emphases added):

The constant expression shall be an integer constant expression. It shall evaluate to a valid fundamental alignment,

The expression math_errhandling & MATH_ERREXCEPT shall evaluate to a nonzero value.

There may be at most one default label in a switch statement. (Any enclosed switch statement may have a default label or case constant expressions with values that duplicate case constant expressions in the enclosing switch statement.)

The defined macros expand to integer constant expressions with values ...

The values given in the following list shall be replaced by implementation-defined constant expressions with values ...

... the expression is a valid integer constant expression with value one

Are "with value" and "evaluate to value" synonyms?

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 2
    Maybe it's just as simple as: `1` has value 1, whereas `1 + 1` is an integer constant expression evaluated to 2. – Lundin Mar 14 '23 at 10:46
  • 1
    IMO "with value" means the value after evaluation. For instance the standard has this note: ".... `static int i = 2 || 1 / 0;` the expression is a valid integer constant expression with value one." I read that as "` 2 || 1 / 0` evaluate to the value one" – Support Ukraine Mar 14 '23 at 11:28
  • 1
    @Lundin, all the examples presented pertain to constant expressions (not necessarily *constants*). It appears to me that the spec simply uses two distinct forms for conveying the same idea. I'm inclined to think that the distinction is editorial / English-language based, not technical. – John Bollinger Mar 14 '23 at 13:19

1 Answers1

1

Are "with value" and "evaluate to value" synonyms?

TL;DR: yes.


The language spec does not formally define the term "evaluate", so we must rely on conventional English definitions, such as this one from Merriam-Webster:

to determine or fix the value of

In more mathematical context, such as applies to C expressions, I understand "<Y> evaluates to <X>" to mean that <X> is the value determined when <Y> is evaluated.

The spec does define "value", but that definition does not shed much light on the question at hand.

I checked all the appearances of "with value <X>" / "with values that" and "evaluate to" in the C11 language spec (since that's the version referenced in the question). The former appears 10 times:

There are also one or two closely-related forms, such as "with (positive) values that" in E/6.

The "evaluate to" form appears 9 times:

Many of those, in both categories, are about the values of constant expressions, but only a couple are related specifically to the values of constants. The rest are about the values of expressions that are not necessarily constant expressions.

As far as I can determine, the two forms are used interchangeably with respect to C language concepts. The only distinction I see is around English grammar and usage. The "with value <X>" form is used when a requirement on the value of an expression is presented in the context of a broader statement about the expression. The "evaluate to <X>" form is used when a requirement on the value of an expression is presented as a standalone statement. The question presents several good examples of each.

This is an editorial choice. It has no technical significance.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thanks! Re: "broader statement and standalone statement": interesting observation. Extra: 1) As I understand, the following terms (widely used in C11) are (full) synonyms: "same", "match" / "matching", "identical". 2) Is it OK that standards use synonyms? – pmor Mar 16 '23 at 11:02
  • @pmor, (1) I am not prepared at this time, in this context, to do the same kind of analysis of that set of terms, but I am inclined to think that yes, those terms are used more or less interchangeably in the C language spec. (2) I don't see why not. – John Bollinger Mar 16 '23 at 13:10