Back to all reviewers

Use utility macros

dotnet/runtime
Based on 2 comments
C

Use predefined utility macros for common operations instead of repeating manual calculations throughout your code. This improves readability, consistency, and reduces the likelihood of errors in calculations.

Code Style C

Reviewer Prompt

Use predefined utility macros for common operations instead of repeating manual calculations throughout your code. This improves readability, consistency, and reduces the likelihood of errors in calculations.

For example, instead of manually calculating array sizes:

// Don't do this
if (wcsncmp(path, DevicePathPrefix, sizeof(DevicePathPrefix) / sizeof(WCHAR) - 1) == 0)
    return NULL;

// Do this instead
if (wcsncmp(path, DevicePathPrefix, STRING_SIZE(DevicePathPrefix) - 1) == 0)
    return NULL;

Check for existing utility macros in your project (such as ARRAY_SIZE, STRING_SIZE in util.h) before writing common calculations. This practice ensures consistent implementation across the codebase and makes future maintenance easier by centralizing any changes needed to these calculation patterns.

2
Comments Analyzed
C
Primary Language
Code Style
Category

Source Discussions