concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

Fix BLOCK_SIZE macro conflict with system headers

Open caomengxuan666 opened this issue 8 months ago • 1 comments

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.

caomengxuan666 avatar Mar 09 '26 08:03 caomengxuan666

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.

cameron314 avatar Mar 09 '26 16:03 cameron314