Convert C_ASSERT to static_assert throughout codebase
This PR converts all C_ASSERT usages to modern static_assert throughout the XDP for Windows codebase. Modern build toolchains support static_assert which provides better error messages and is part of the C11/C++11 standards.
Changes Made
- 72 total C_ASSERT instances converted across the entire codebase
- Used
static_assertconsistently for all files (C, C++, and headers) - Added descriptive error messages to all static assertions for better debugging
- Removed conditional compilation blocks that previously distinguished between C and C++ usage
Files Updated
API Headers (25 instances)
-
published/external/xdpapi.h- XDP API size assertions -
published/external/afxdp.h- AF_XDP structure size assertions - All
published/external/xdp/*.hheaders - Extension and datapath structure assertions
Test Files (21 instances)
-
test/functional/taef/tests.cpp- API version assertions -
test/functional/lib/tests.cpp- Buffer and connection structure assertions -
test/pktfuzz/pktfuzz.c- Frame and buffer layout assertions -
test/fakendis/polldpc.c- NDIS structure size assertions
Source Files (26 instances)
-
src/xdplwf/- LWF driver alignment and offset assertions -
src/xdp/xsk.c- XSK/XDP structure compatibility assertions -
src/rtl/inc/xdprefcount.h- Reference counting size assertions
Example Changes
Before:
C_ASSERT(sizeof(XDP_BUFFER) == 16);
After:
static_assert(sizeof(XDP_BUFFER) == 16, "XDP_BUFFER must be exactly 16 bytes");
The conversion maintains identical functionality while providing better error messages and using modern C/C++ standards consistently across the entire codebase.
Fixes #765.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
@mtfriesen 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.
I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.
@copilot always use static_assert and do not use _static_assert
@copilot always use static_assert and do not use _static_assert
Updated all static assertions to use static_assert consistently throughout the codebase. Removed conditional compilation blocks and replaced all 72 instances of _Static_assert with static_assert as requested. See commit aa3d09b.