Skip to content

C Coding Guidelines

Bernhard Manfred Gruber edited this page May 26, 2025 · 1 revision

CCCL C++ Coding Guidelines

General

  1. Always use entities from cuda::std:: over std::. They work in host and device code and help testing our implementation.
  2. Use CCCL internal macros over compiler/vendor-specific keywords. E.g., use _CCCL_HOST_DEVICE instead of __host__ __device_. This excludes examples and documentation.
  3. Fully qualify any reference to a libcu++ entity. Prefer ::cuda::std::, or _CUDA_VSTD::, over just cuda::std. This avoids ambiguities when users define their namespaces called cuda.
  4. Doxygen comments should start with //!
  5. Macros for function attributes, like _CCCL_HOST_DEVICE, should be ordered before declaration specifiers like constexpr or static
  6. Don't include libcu++ detail headers (starting with __) in downstream projects (like CUB, Thrust, etc.). Always prefer the public headers.

libcu++

  1. Always use the corresponding namespace macro to refer to a libcu++ entity over qualifying with a libcu++ namespace. E.g., use _CUDA_VSTD::enable_if over cuda::std::enable_if.
  2. Always fully qualify function calls, even to functions in the same namespace.
  3. Defaulted constructors should be marked with _CCCL_HIDE_FROM_ABI
  4. libcu++ headers like <cuda/foo> are strict supersets of <cuda/std/foo> and thus always include the corresponding <cuda/std/...> header.
Clone this wiki locally