Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the __COUNTER__ macro instead of __LINE__ #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aedrax
Copy link

@aedrax aedrax commented Jan 12, 2022

This fixes the issue where a compiler puts multiple case statements on the same line and then has a conflict between the two.

For example, for whatever reason, somebody wanted to put

async_yield; async_yield;

They wouldn't be able to because it would expand into

*_async_k = 5; return ASYNC_CONT; case 5:; *_async_k = 5; return ASYNC_CONT; case 5:;

but this will (effectively) expand into:

*_async_k = 3; return ASYNC_CONT; case 3:; *_async_k = 5; return ASYNC_CONT; case 5:;

For what it's worth, __COUNTER__ is not in the C standard but is in most compilers

This fixes the issue where a compiler puts multiple case statements on
the same line and then has a conflict between the two
@naasking
Copy link
Owner

Hmm, I like the idea but don't like that it's not standard. I created async.h for use on my microcontroller projects that come with their own C compilers. Then again, not really a big deal to run the gcc/clang preprocessor and then the C compiler on the preprocessed source, so I'll have to think about this...

@shakna-israel
Copy link

What about a fallback using something like...

#ifndef __COUNTER__
    #define __COUNTER__ __LINE__
#endif

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.

3 participants