On 24/05/2026 12:49, Chris M. Thomasson wrote:
Anybody up for some C, if so, C the following:
It's nice to have an actual C question, though it is more about style
and preference. But please cut the childish babble - it does not add
anything useful.
________________
int main(void)
{
ÿÿÿ int hello_0 = 12;
ÿÿÿ {
ÿÿÿÿÿÿÿ int hello_1 = 30;
ÿÿÿÿÿÿÿ int hello_2 = hello_0 + hello_1;
ÿÿÿ }
ÿÿÿ return 0;
}
________________
Declare where needed vs, all, well, we know, up front?
A lot of people like to declare variables only when they are ready to be initialised. And it is quite common to avoid changing variables
afterwards, unless there is obvious need (like a loop index) or it is
clearer in code - if you are calculating a new value, it can be helpful
to introduce a new variable with a new name for the purpose. This can
make it easier to see in code where things come from - when you are
looking at later lines in the function and wondering where the variable "hello" is set, if it is only set in one line of the code then you can't accidentally miss a later change.
Obviously you need to pick decent names for this - suffixing a number is unlikely to be a good strategy for clear code.
It is also worth declaring these variables as "const". Then everyone - authors, readers and compiler - can clearly see that they are not changing.
Using new variables rather than re-using old variables does mean that
you need an optimising compiler for efficient results, as the compiler
will do the lifetime analysis and re-use registers or stack slots - but there's never much point thinking much about efficiency while using a non-optimising compiler.
--- PyGate Linux v1.5.14
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)