Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

modern-c-cpp-standards

БесплатноБез исполняемых скриптовНе проверен

Modern C and C++ standards skill for C23, C2y and C++20/26. Use when a compiler upgrade changes the default language standard, migrating code to C23 or C++20…

mohitmishra786от mohitmishra786★ 307 звёзд на GitHub

Об этом скилле

Modern C and C++ Standards

Purpose

Guide agents through current C and C++ standards on real compilers (checked with GCC 14/15/16.2 and Clang 23.1): changed defaults, C23 and C2y features, the C++20 default in GCC 16, C++26 reflection and contracts, library hardening, and feature detection.

Triggers

  • "My code stopped compiling after upgrading to GCC 15/16"
  • "What changed in C23 and how do I use #embed / nullptr / ckd_add?"
  • "How do I try C++26 reflection?"
  • "How do C++26 contracts (pre, post, contract_assert) work?"
  • "Which compiler supports which C++26 feature?"
  • "How do I detect language features portably?"

Workflow

1. Which standard am I compiling with?

Compiler Default C Default C++
GCC 14 gnu17 (201710L) gnu++17 (201703L)
GCC 15 gnu23 (202311L) gnu++17
GCC 16 gnu23 gnu++20 (202002L)
Clang 23 gnu17 gnu++17
# Print the effective standard version macros
gcc -dM -E -x c /dev/null | grep __STDC_VERSION__
g++ -dM -E -x c++ /dev/null | grep '__cplusplus '

# Pin the standard in the build instead of relying on defaults
gcc -std=gnu17 ...      # CMake: set(CMAKE_C_STANDARD 17), set(CMAKE_CXX_STANDARD 17)
Build broke after a compiler upgrade?
├── C file → new default is C23 → section 2 (or pin -std=gnu17 while fixing)
├── C++ file with GCC 16 → new default is C++20 → section 4 (or pin -std=gnu++17)
└── Neither → check release notes for new warnings promoted to errors

2. Moving C code to C23

C17 code C23 behaviour Fix
typedef int bool; / #define bool int bool, true, false are keywords: 'bool' cannot be defined via 'typedef' Remove; use the keyword (or <stdbool.h> is a no-op)
int f(); then f(1, 2) () means (void): too many arguments to function 'f' Write the full prototype
K&R definitions int f(a, b) int a, b; {...} Removed from C23 Convert to prototype form
Identifiers nullptr, constexpr, typeof, static_assert, alignas, thread_local Now keywords Rename

GCC 15/16 accept the old code with -std=gnu17; use that as a stopgap, not a fix.

3. C23 features

// c23.c — gcc -std=c23 (GCC 15+), clang -std=c23
#include <stdbit.h>
#include <stdckdint.h>
#include <stdio.h>

constexpr int N = 4;                     // constexpr objects
static const unsigned char blob[] = {
#embed "c23.c" limit(8)                  // embed a file's bytes at compile time
};

nodiscard static int twice(int x) { return 2 * x; }

int main(void) {
    int *p = nullptr;                    // nullptr / nullptr_t
    typeof(N) arr[N] = {};               // typeof, empty initializer
    bool ok = true;                      // bool/true/false are keywords
    auto y = twice(21);                  // auto type inference
    _BitInt(12) small = 2047wb;          // bit-precise integers
    unsigned u = 0b1010'0000;            // binary literal + digit separators
    int sum;
    if (ckd_add(&sum, 2147483647, 1))    // checked arithmetic, returns true on overflow
        puts("overflow detected");
    printf("%d %d %d %u %d\n", (int)sizeof arr, y, ok, stdc_count_ones(u), (int)small);
    printf("embed first byte: %c\n", blob[0]);
    return p == nullptr ? 0 : 1;
}

#embed needs GCC 15+ (GCC 14 reports invalid preprocessing directive #embed). Clang 23 builds this file with -std=c23. <stdbit.h> and <stdckdint.h> come from the C library: glibc 2.39+ ships <stdbit.h>, so a new compiler on an older glibc still fails on that include.

C2y (next C standard) in GCC 16 with -std=c2y:

int a[7];
printf("%zu\n", _Countof(a));            // element count, replaces sizeof(a)/sizeof(a[0])
if (int n = 3; n > 2) { /* ... */ }      // declarations in if conditions

4. GCC 16: C++20 by default

Code that built as C++17 can fail or warn under C++20:

C++17 code C++20 result Fix
const char* s = u8"text"; error: u8 literals are const char8_t[] Use char8_t, or -fno-char8_t temporarily
struct A { A() = delete; int x; }; A a{1}; error: a user-declared constructor makes it a non-aggregate Remove the declaration or add a real constructor
Non-const bool operator==(const T&) warning: ambiguous with the reversed candidate Make operator== const
volatile int v; v++; warning: deprecated (-Wvolatile) v = v + 1 or use atomics

5. C++26 status

C++26 was finalized by WG21 in March 2026, but the ISO DIS ballot failed on 23 October 2026, mainly over contracts. WG21's November 2026 meeting is deciding how to proceed. Treat contracts as subject to change. Implementations are experimental and behind flags:

Feature GCC 16.2 Clang 23.1 (upstream)
Static reflection (P2996) -std=c++26 -freflection No (Bloomberg
Полный SKILL.md на GitHub

Установить modern-c-cpp-standards в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл modern-c-cpp-standards?

Modern C and C++ standards skill for C23, C2y and C++20/26. Use when a compiler upgrade changes the default language standard, migrating code to C23 or C++20, using C23 features such as nullptr, constexpr, #embed and checked arithmetic, trying C++26 static reflection or contracts, or detecting language features portably. Activates on queries about C23, C2y, C++26, -std=c23, -std=c++26, -freflection, -fcontracts, pre/post/contract_assert, std::meta, #embed, _BitInt, stdckdint.h, inplace_vector, or __cpp feature-test macros.

Как установить скилл modern-c-cpp-standards?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл modern-c-cpp-standards запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить modern-c-cpp-standards с