Sujet : Re: on changing paradigm of assign call
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 02. Sep 2024, 11:03:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vb42gn$1gbbm$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 02/09/2024 02:45, Lawrence D'Oliveiro wrote:
On Sun, 01 Sep 2024 16:15:37 +0200, fir wrote:
int x = foo()
>
annoying is especially this "=" sign as this is not quite assignment
imo
The original symbol as used in Algol-like languages was “:=”. While C
copies quite a few features from the Algol family, it made the
questionable decision to shorten the assignment operator to “=”,
ostensibly to save typing. Which meant they had to invent a different
symbol, “==”, to denote an equality comparison.
The original symbol in FORTRAN, which came before Algol, was "=" for assignment (and .EQ. for equality)
BASIC, which came long before C, used "=" for both. It could do that because it didn't allow assignment inside an expression.
(Meanwhile I use '=' for equality, for defining new named entities, and for compile-time assignments. Runtime assignments used ':=':
static int a = 100 # inside function
int b := 200
The line is blurred a little in dynamic code when some '=' assignments need to be done as execution starts.
In C though it gets confusing using the same symbol for each;
static int a = 100; // Initialised once only (and likely before
// execution starts)
int b = 200; // Initialised every time it is encountered)