Skip to content

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);
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant