Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Conversation

brightprogrammer
Copy link
Owner

It's amazing how posting your work on internet brings some really good suggestions sometimes to the problems that you might've never been able to solve on your own! Foreach macros inside MisraStdC have been syntactically every ugly. I recently posted my repo in hackernews and got a really nice suggestion.

Now foreach macros can be used like actual for loops without any compromise!

Examples :

    // Use VecForeach for iterating over entries
    VecForeach(&entries, e) {
        if (last_value == e.value - 1) {
            StrWriteFmt(&code, "    {},\n", e.name.data);
        } else {
            StrWriteFmt(&code, "    {} = {},\n", e.name.data, e.value);
        }
        last_value = e.value;
    };

    // Use VecForeach for iterating over entries
    VecForeach(&entries, e) {
        const char* caseTemplate = "        case {} : {{return \"{}\";}}\n";
        StrWriteFmt(&code, caseTemplate, e.name.data, e.str.data);
    };

@brightprogrammer brightprogrammer merged commit 4b6f310 into master Sep 24, 2025
8 of 10 checks passed
@brightprogrammer brightprogrammer deleted the foreach_iterators_syntax_improvements branch September 24, 2025 04:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant