| title | Quick Start Guide |
|---|---|
| description | Getting started with dasae-headers for safer C programming |
| created | 2025-04-01 |
| updated | 2025-04-13 |
| version | v0.1.1 |
| target_version | pre-alpha |
This guide will help you get started with dasae-headers, a modern extension language for safer and more productive C programming.
- C17 compatible compiler (clang 11+, gcc 8+, or MSVC 19.20+)
- Git (for obtaining the source)
Clone the repository to your local machine:
git clone https://github.com/coding-pelican/dasae-headers.git
cd dasae-headersThe dh-c build tool simplifies project management, building, and testing of dasae-headers projects.
- Open a PowerShell prompt as Administrator
- Navigate to the dasae-headers directory
- Run the installation script:
.\install-dh-c.ps1- Restart your terminal or PowerShell session
- Open a terminal
- Navigate to the dasae-headers directory
- Make the installation script executable and run it:
chmod +x install-dh-c.sh
./install-dh-c.sh- Restart your terminal session or source your profile
Create a new project using the dh-c tool:
dh-c project my-project
cd my-projectThis command creates a standard project structure with all necessary configuration files.
The dh-c tool creates the following directory structure:
my-project/
├── include/ # Project-specific headers
├── src/ # Source files
│ └── main.c # Main entry point
├── lib/ # Third-party libraries
├── build/ # Build output (created during build)
├── .clangd # Language server configuration
├── .clang-format # Code formatter configuration
└── .vscode/ # VS Code configuration
└── tasks.json # Build tasksLet's create a simple "Hello, world!" program:
- Open
src/main.cand replace its contents with:
#include "dh/main.h"
#include "dh/Str.h"
fn_(dh_main(Sli$Sli_const$u8 args), Err$void $scope) {
// Create a string literal
let hello = Str_l("Hello, dasae-headers!");
// Print to console with newline
Str_println(hello);
// Return success
return_ok({});
} $unscoped;- Build and run the program:
dh-c build dev # Build in development mode
dh-c run dev # Run the programfn_- Function declarationSli$Sli_const$u8- Slice of constant strings (command-line arguments)Err$void- Error result type with void payload$scope- Function with extended scope for return payloadlet- Type inference for variable declarationStr_l- String literal creationreturn_ok- Successful return with payload$unscoped- End of function's extended scope
dasae-headers provides both traditional C-style and modern type inference approaches for variable declaration:
// Basic form (immutable)
const i32 count = 10;
// Type inference (immutable)
let count = 10; // const i32 inferred
// Type specified (immutable)
let_(count, i32) = 10; // const i32
// Basic form (mutable)
i32 number = 42;
// Type inference (mutable)
var number = 42; // i32 inferred
// Type specified (mutable)
var_(number, i32) = 42; // i32Automatic resource cleanup using defer:
fn_(readFile(Sli_const$u8 path), Err$Str $guard) {
let_(file, FILE*) = fopen(path.ptr, "r");
if (file == null) {
return_err(fileError("Could not open file"));
}
// This will execute when the function exits
defer_(let_ignore = fclose(file));
// Process file...
return_ok(fileContents);
} $unguarded;Explicit error handling with the try_ pattern:
fn_(processData(void), Err$void $scope) {
// Call function that may fail and propagate error
let result = try_(getData());
// Process result...
return_ok({});
} $unscoped;Safe handling of nullable values:
fn_(findUser(i32 id), Opt$User $scope) {
if (id <= 0) {
return_none(); // No user found
}
User user = getUserById(id);
return_some(user); // User found
} $unscoped;
// Usage
if_some(findUser(42), user) {
// User exists, process user
} else_none {
// Handle not found case
}The dh-c tool provides a simple and consistent way to build and run your projects.
Build your project with one of the predefined configurations:
dh-c build dev # Development mode (debug, no optimization)
dh-c build test # Test mode
dh-c build release # Release mode (optimized)
dh-c build performance # Maximum performance
dh-c build embedded # Size optimization
dh-c build micro # Extreme size optimizationRun your application:
dh-c run dev # Build and run in development modePass arguments to your program:
dh-c run dev --args="arg1 arg2"Run tests:
dh-c test # Run all testsShow executed commands:
dh-c build dev --show-commandsEnable output suffix for build configurations:
dh-c build dev --use-output-suffixGet help:
dh-c --helpdasae-headers includes built-in debug features:
debug_assert_true(condition, "Error message");
debug_assert_fmt(0 < count, "Invalid count: %d", count);The dh-c tool creates VSCode configuration files for your project:
Press Ctrl+Shift+B(default shortcut) to access build tasks:
dh>build project- Build the projectdh>run project- Build and run the projectdh>test project- Run testsdh>execute project- Run without rebuilding
Now that you've set up a basic project, you can explore:
- Core Concepts - Fundamental principles like memory safety, error handling, and type system
- API Reference - Comprehensive documentation for all library modules
- Examples - Practical code samples demonstrating library features
- Tutorials - Step-by-step guides for learning specific techniques
Happy coding with dasae-headers!