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

compile: avoid min macro pollution #942

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

Conversation

zhangjian3032
Copy link
Contributor

The generic min macro in util.h is too common and can conflict with other libraries. Rename it to nvme_min to avoid pollution.

Before renaming the macro, the cpp's std::min will fail to compile.

./test/cpp.cc: In function ‘int min_compile_test()’:
../src/nvme/util.h:563:19: error: expected unqualified-id before ‘(’ token
  563 | #define min(x, y) ((x) > (y) ? (y) : (x))

The generic min macro in util.h is too common and can conflict with
other libraries. Rename it to nvme_min to avoid pollution.

Before renaming the macro, the cpp's std::min will fail to compile.
```
./test/cpp.cc: In function ‘int min_compile_test()’:
../src/nvme/util.h:563:19: error: expected unqualified-id before ‘(’ token
  563 | #define min(x, y) ((x) > (y) ? (y) : (x))
```

Signed-off-by: Jian Zhang <[email protected]>
@@ -560,7 +560,7 @@ char *kv_keymatch(const char *kv, const char *key);
*/
char *startswith(const char *s, const char *prefix);

#define min(x, y) ((x) > (y) ? (y) : (x))
#define nvme_min(x, y) ((x) > (y) ? (y) : (x))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not expose this macro at all. And there should be already the min macro from the ccan 'library'. Can you drop this one and include the ccan/minmax.h header in the c files?

static int max_compile_test()
{
return std::max(1, 2);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated with the above change.

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.

2 participants