Void Type — void
Overview
void is a C FFI-only return type in Nitpick. It indicates that a C function returns
no value. Unlike most languages, void is not a general-purpose "no value" type in
Nitpick — that role is served by NIL.
Important: You cannot declare
voidvariables, usevoidas a function return type outsideexternblocks, or capture the result of a void-returning function.
Usage: Extern Blocks Only
extern "libc" {
func:free = void(int64:ptr); // valid: C function returns nothing
func:printf = void(string:fmt, ..?); // valid: variadic C function
};
What Gets Rejected
void as a Nitpick function return type
func:do_nothing = void() { // ❌ REJECTED
// ...
};
Error: void return type only allowed in extern blocks. Use NIL for no-value returns in
Nitpick code.
Capturing the result of a void function
extern "libc" {
func:free = void(int64:ptr);
};
int32:result = free(ptr); // ❌ NITPICK-VOID-001
Error: cannot use the result of a void-returning function as an initializer — void
functions produce no value.
Declaring void variables
void:x = 42; // ❌ Parser error
Error: Cannot declare variables of type 'void'.
NIL vs void — When to Use Which
This is the most common point of confusion for new Nitpick programmers:
NIL |
void |
|
|---|---|---|
| What it is | A value meaning "nothing" | A type meaning "no return" |
| Where it's valid | Anywhere a value is expected | Only in extern block return types |
| Use case | "This function has no meaningful return" | "This C function returns nothing" |
| Result wrapping | pass(NIL) → Result<NIL> |
Not wrapped — raw C ABI |
| Can be stored | Yes (any:x = NIL;) |
No (cannot declare void variables) |
| Example | func:f = int32() { pass(NIL); }; |
extern func:f = void(int32:x); |
The Design Rationale
Nitpick's Result system wraps every non-extern function return in Result<T>. The NIL
value fits naturally into this system — pass(NIL) produces a successful Result<NIL>.
void exists solely for C compatibility. C's void return type means "no return value at the
ABI level" — there is literally no register or stack slot allocated for a return value. This is
a fundamentally different concept from "I am returning a value that represents nothing."
Diagnostics
| ID | Trigger | Guidance |
|---|---|---|
| NITPICK-VOID-001 | int32:x = void_func(); |
Cannot capture void return — void produces no value |
| NITPICK-VOID-002 | x = void_func(); |
Cannot assign void return — void produces no value |
Related
- FFI Guide — full FFI interoperability guide
- Result Type — Nitpick's Result
system (all non-extern returns) - Special Values — NIL, ERR, NULL, unknown