C-Next
raw JSON → 0.2.16 verified Fri May 01 auth: no javascript
C-Next is a transpiler (v0.2.16) that compiles a safer C dialect to standard C99 for embedded systems. It aims to follow TypeScript's adoption model: incremental, no new runtime, and readable output for existing toolchains (GCC, Clang, IAR). Key features include type-safe register bindings, automatic bit-indexing, and MISRA-friendly preprocessor compatibility. Unlike Rust or other memory-safe languages, C-Next preserves full use of existing C debuggers, profilers, and optimization passes. Release cadence is frequent (minor updates weekly). Current status: working transpiler verified on Teensy and STM32 hardware.
Common errors
error Error: Node.js version 16.x is not supported. Please use >=18.20.0 ↓
cause Running c-next on Node.js < 18.20.0
fix
Update Node.js to 18.20.0 or later, or use a version manager like nvm.
error SyntaxError: Unexpected token 'namespace' ↓
cause Using deprecated `namespace` keyword instead of `scope`.
fix
Replace
namespace with scope in the .cnx source file. error TypeError: Cannot read properties of undefined (reading 'fields') ↓
cause Register definition missing access qualifiers or using wrong syntax.
fix
Ensure register fields have valid types (e.g., u32, u16) and access (rw, wo, ro). Example:
DR: u32 rw @ 0x00. error error: expected identifier or '(' before '=' token ↓
cause Using `=` for variable assignment in C-Next source.
fix
Use
<- instead of = for variable bindings: u32 LED_BIT <- 3; Warnings
breaking In v0.2.x, `register` syntax changed: fields now require bit-width and access qualifiers (e.g., `u32 rw`). Old style without types not supported. ↓
fix Update register definitions to include type and access qualifiers: `register NAME @ addr { FIELD: u32 rw @ offset }`.
breaking `scope` replaces `namespace`; `namespace` is no longer valid as of v0.2.0. ↓
fix Replace `namespace` with `scope` in all .cnx files.
breaking Variable assignment syntax changed: use `<-` instead of `=` for binding constants. ↓
fix Replace `=` with `<-` for variable definitions like `u32 LED_BIT <- 3;`.
gotcha C-Next requires Node.js >=18.20.0. Using older Node versions will fail at runtime. ↓
fix Update Node.js to >=18.20.0, or use npx which will use the system's default Node version.
gotcha The generated C code uses `volatile uint32_t*` for registers. Ensure your toolchain supports C99 stdint.h. ↓
fix Include <stdint.h> or equivalent in your project; C-Next output relies on uint32_t and similar types.
Install
npm install c-next yarn add c-next pnpm add c-next Imports
- c-next
npx c-next generate file.cnx - register wrong
register MY_REG @ 0x4000 { int field; }correctregister MY_REG @ 0x4000 { FIELD: u32 rw @ 0x00 } - scope wrong
namespace MyScope { ... }correctscope MyScope { void func() { ... } }
Quickstart
// Install globally or use npx
npm install -g c-next
# Create a file: blink.cnx
# Register binding with type-safe access
register GPIO7 @ 0x42004000 {
DR: u32 rw @ 0x00,
DR_SET: u32 wo @ 0x84,
DR_TOGGLE: u32 wo @ 0x8C,
}
u32 LED_BIT <- 3;
scope LED {
void toggle() {
// Type-aware bit indexing on write-only register
GPIO7.DR_TOGGLE[LED_BIT] <- true;
}
}
# Transpile to C
c-next generate blink.cnx
# Output: blink.h, blink.c