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

Incorrect macro expansions #331

Closed
KoenigKrote opened this issue Jul 24, 2020 · 1 comment
Closed

Incorrect macro expansions #331

KoenigKrote opened this issue Jul 24, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@KoenigKrote
Copy link

Invalid semicolons get inserted when using certain define macros.

For example, the well known do { stuff; } while (0) macro wrapper trick expands incorrectly.'

Example:

#define foo(x) do { return (x); } while (0)

int f(int num)
{
  if (num > 0)
    foo(num);
  else
    return num * num;
}

Expands into

int f(int num)
{
  if(num > 0) do {
    return (num);
  } while(0);
  
  ;
  else return num * num; 
}

Which has incorrectly inserted an additional semicolon between the if/else blocks (or automatically inserted one after while(0), causing the original semicolon to be pushed between blocks)

@andreasfertig
Copy link
Owner

Hello @KoenigKrote,

nice catch! Thanks for reporting this. The issue comes from the do-while inside an if or else. The macro has nothing to do with it. A fix is on its way.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Jul 24, 2020
andreasfertig added a commit that referenced this issue Jul 24, 2020
Fixed #331: Removed additional semi-colon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants