Skip to content

Fix BLOCK_SIZE macro conflict with system headers#443

Open
caomengxuan666 wants to merge 1 commit intocameron314:masterfrom
caomengxuan666:fix-block-size-macro-conflict
Open

Fix BLOCK_SIZE macro conflict with system headers#443
caomengxuan666 wants to merge 1 commit intocameron314:masterfrom
caomengxuan666:fix-block-size-macro-conflict

Conversation

@caomengxuan666
Copy link

When including system headers like <linux/fs.h> which define BLOCK_SIZE as a macro (usually 1024), it conflicts with the BLOCK_SIZE constant in concurrentqueue. This causes compilation errors:

blockingconcurrentqueue.h:39:29: error: expected unqualified-id before numeric constant
   39 |         static const size_t BLOCK_SIZE = ConcurrentQueue::BLOCK_SIZE;
      |                             ^~~~~~~~~~

Add push/pop macro guards around the entire file to temporarily undefine BLOCK_SIZE if it exists, and restore it after.

This is a common issue when using concurrentqueue with io_uring or other Linux headers that define BLOCK_SIZE. The fix uses #pragma push_macro/pop_macro which is supported by GCC, Clang, and MSVC.

Testing: Tested with the following code:

#define BLOCK_SIZE 1024  // Simulate system macro
#include "concurrentqueue.h"
#include "blockingconcurrentqueue.h"

int main() {
    moodycamel::ConcurrentQueue<int> q;
    return 0;
}

The code compiles successfully and BLOCK_SIZE is correctly restored after including the headers.

When including system headers like <linux/fs.h> which define BLOCK_SIZE
as a macro (usually 1024), it conflicts with the BLOCK_SIZE constant in
concurrentqueue. This causes compilation errors.

Add push/pop macro guards around the entire file to temporarily undefine
BLOCK_SIZE if it exists, and restore it after.

This is a common issue when using concurrentqueue with io_uring or other
Linux headers that define BLOCK_SIZE. The fix uses #pragma push_macro/
pop_macro which is supported by GCC, Clang, and MSVC.
@caomengxuan666 caomengxuan666 force-pushed the fix-block-size-macro-conflict branch from 9c96ccb to f8fda36 Compare March 9, 2026 08:27
@cameron314
Copy link
Owner

Can't merge this, sorry. BLOCK_SIZE is part of the public API, it's not just used in the header (otherwise I could just rename it).

If you're not using BLOCK_SIZE in your code to initialize queue traits, just include fs.h after concurrentqueue.h.

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