Elektrine lite

← Feed

@Steel_Virgin@eldritch.cafe

Post #1981533

2026-05-04 10:06 UTC

@typeswitch excuse me, I'm a student that burnt out six years ago, traumatized to a point I can't get my hands on the keyboard if there's an IDE opened, so, I'm not an expert in C. So I'm quite confused by (it.value = (p)[index], true); I mean, I dont understand the syntax. 1- I don't remember what = is supposed to return. I feel like it shouldn't return anything and, trying to read the value of an assignation wouldn't be accepted by the compiler or perhaps would return something that you would very rarely want to have access to like low level thing or idk. 2- I'm confused by the (assignation, bool) syntax. if we imagin = returns a boolean, that sort of looks like a python tuple. But, that's very not a C thing. So that's why I'm confused. from writing this and reading myself back, I feel like the value returned by this expression would be true and that the assignation would be executed but its "value" would never be tested. from what I just said I can't imagine anything other than (do this, return that), but it feels like a strange and very specific syntax that doesn't belong in C… (but the more I think about it, the more the strangeness and specificness are 100% C caracteristics) So I think I need a bit of explanation about that.

Replies (1)

  • @firefly@frogs.lgbt 2026-05-04 12:05

    @Steel_Virgin @typeswitch for (1), assignment evaluates to the new value after the assignment (so `(p)[index]` here). for (2), `(do this, return that)` is pretty much the behaviour here: https://en.wikipedia.org/wiki/Comma_operator it's kind of important for C reasons since it acts as a sequence point (meaning the left-hand side is guaranteed to be fully evaluated before the right-hand side)

    Open ##1981534