Re:C uses "&" for the address-operator because 'ampersand so...
by a_e_k on Tuesday October 10, 2023 @01:01PM
(#37834632)
Another good real-world one that I've done is something like:
Personally, I like the flexibility.
[ Parent
| on HN ]
Re:C uses "&" for the address-operator because 'ampersand so...
by bxparks on Tuesday October 10, 2023 @01:52PM
(#37835209)
Heh, hopefully not too often. First I thought this loops 128 times. Then 7 times. Then 8 times. Then I thought "undefined behavior" if bit is a uint8_t. But then I thought, I don't have freaking clue because I can't keep all of C's implicit casting and arithmetic operation rules in my head.
Re:C uses "&" for the address-operator because 'ampersand so...
by adrian_b on Tuesday October 10, 2023 @02:27PM
(#37835640)
A better syntax for loops with geometric progressions like this would be obtained by modifying the syntax for writing arithmetic progressions (e.g. "a:b:c") by using a different separator symbol.
For example, if the separator for geometric progressions would be ":>", your loop example would become "for bit in 1:>128:>2". Another example of (non-ASCII) separator would be "for bit in 1⋮128⋮2"