Elektrine lite

← Feed

@typeswitch@gamedev.lgbt

Post #1947127

2026-05-04 00:03 UTC

"C doesn't have iterators-- (Part 3)" https://godbolt.org/z/d47Por9eT

Replies (11)

  • @idiot@mastodonapp.uk 2026-05-04 07:58

    @typeswitch@gamedev.lgbt surely n should be internal?

    Open ##1947126

  • @typeswitch@gamedev.lgbt 2026-05-04 01:59

    "C doesn't have iterators-- (Part 999)" https://godbolt.org/z/aE6Gc8qb5

    Open ##1961720

  • @milo@types.pl 2026-05-04 00:11

    @typeswitch im not convinced that C has iterators, since none of these macros are built by composing the other macros

    Open ##1981501

  • @clarfonthey@toot.cat 2026-05-04 00:23

    @typeswitch the things people get up to without hygenic macros

    Open ##1981508

  • @typeswitch ah yes i too have a foreach macro, sadly can’t nest them because of the index though

    Open ##1981511

  • @jens@social.finkhaeuser.de 2026-05-04 06:18

    @typeswitch Nice! Iterators in C++ are of course modelled on C pointers, so that part was not too surprising. The anonymous struct hack is cute, though. I wouldn't have thought of that, I don't think!

    Open ##1981526

  • @aka_dude@mk.phreedom.club 2026-05-04 07:28

    @typeswitch@gamedev.lgbt map, filter, reduce? iterators have to be values. this is just glorified for-i.

    Open ##1981529

  • @Steel_Virgin@eldritch.cafe 2026-05-04 10:06

    @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.

    Open ##1981533

  • @zardoz03@mastodon.online 2026-05-04 17:23

    @typeswitch i am not happy with this but, for foreach though, it wouldn't work with an iterator with a different type but the same interface? unless theres some forked version of chibicc/tcc that makes types structural.

    Open ##1981536

  • @typeswitch that looks similar to what I used to write. (...before switching to C++ to do exactly the same but with templates)

    Open ##1981538

  • @pancake@infosec.exchange 2026-05-14 13:41

    @typeswitch@gamedev.lgbt @eniko@mastodon.gamedev.place vala does a similar thing with the glib machinery

    Open ##2805926