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

do {S} while (0) #738

Open
andrew-appel opened this issue Oct 26, 2023 · 0 comments
Open

do {S} while (0) #738

andrew-appel opened this issue Oct 26, 2023 · 0 comments
Assignees

Comments

@andrew-appel
Copy link
Collaborator

A standard idiom in C macros is,

#define foo(..)    do {...} while (0)

The reason for this is to allow one to write the statement foo(...); with a semicolon afterward; if one did instead define foo(...) {...} then the semicolon would have the wrong semantics.

It might be easy and useful to recognize this pattern in Floyd and automatically do a program transformation (perhaps using our Hoare-logic inversion rules) to convert do {S} while (0) into simply S. One problem with that approach is that break and continue within S would have the wrong semantics, so it would only work for statements that don't (syntactically) contain any break or continue.

Perhaps it's worth investigating whether this is easy or hard.

Thanks to @roconnor-blockstream for pointing out this pain point.

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

No branches or pull requests

2 participants