stdc

A zero-friction, minimal-abstraction Standard C Library implementation for Dart.


Designed specifically for C and C++ programmers who want to bring their muscle memory and familiar toolkit into the Dart ecosystem. stdc provides an authentic C experience without forcing you to learn new, convoluted abstractions.

⚡ The Selling Point: Zero Overhead, True Native Performance

You might be wondering: Is this just a slow wrapper mimicking C?

Absolutely not.

When you call a function like stdc.sin(x), you aren't running a slow Dart approximation. Because stdc leverages Dart's VM intrinsics, your code directly compiles down to the exact same highly-optimized native libc (or libm) instructions that a standard C program would execute.

🚀 Getting Started

To install the library, run the following command in your terminal:

For Dart projects:

dart pub add stdc

For Flutter projects:

flutter pub add stdc

(Alternatively, you can manually add stdc: ^1.1.9 to your pubspec.yaml dependencies).

  • Zero Memory Overhead: The stdc namespace is a compile-time constant. It allocates exactly 0 bytes.
  • Bare-Metal Speed: You get the exact same precision, hardware acceleration, and speed as native C.
  • Familiar Architecture: No object instantiation, no complex managers. Just pure, functional C calls.

🧠 The Philosophy

The beauty of stdc lies in its simplicity. You only need to remember one word: stdc.

Instead of dealing with fragmented namespaces like stdio.printf or io.printf, everything is directly accessible through the unified stdc interface. If you know C, you already know how to use this library.

import 'package:stdc/stdio.dart';
import 'package:stdc/math.dart';

void main() {
  // Classic C-style I/O
  stdc.printf("Hello, %s!\n", ["World"]);

  // Raw, native-speed mathematics
  double result = stdc.pow(2.0, 8.0);

  // Mutable string buffers (char*)
  var buffer = CString.fromString("Hello");
  stdc.strcatBuffer(buffer, CString.fromString(" World"));
}

📦 How to Import

There are two ways to use this library, depending on your preference:

1. The "Include All" Approach (Convenience)

Import the main entry point to access all available C headers at once.

import 'package:stdc/stdc.dart';

void main() {
  var num = stdc.sqrt(16.0); 
}

2. The "Specific Header" Approach (Authentic C Style)

Import only the specific headers you need, just like #include <math.h> in C. This keeps your autocomplete clean and only exposes the functions you intend to use.

import 'package:stdc/math.dart';
// import 'package:stdc/stdio.dart'; // (When implemented)

void main() {
  var num = stdc.sqrt(16.0); 
}

🛠 Supported Headers

We are actively expanding our coverage of standard C headers. Currently supported or in development:

  • <math.h> - Core mathematical functions (sin, pow, fabs, sqrt, etc.)
  • <stdio.h> - Standard input/output functions (printf, sprintf, snprintf, puts, getchar, scanf, sscanf, etc.) with full C99 format specifiers: flags (-, +, , 0, #), width, precision, %o, %u, %e, %E, %g, %G, %p
  • <stdlib.h> - Standard library utility functions (strtol, strtod, atoi, rand, abs, qsort, getenv, system, etc.)
  • <string.h> - C-style string manipulation (strcpy, strlen, strcmp, etc.) and mutable buffers (CString, memcpy, memset)
  • <ctype.h> - Character classification (isalpha, isdigit, toupper, etc.)
  • <time.h> - Core time tracking utilities (time, clock, difftime)
  • <assert.h> - Standard C-style runtime assertions (assert)
  • <limits.h> - Core integer limit boundaries (INT_MAX, UINT_MAX, etc.)
  • <float.h> - Floating point limit bounds and epsilons (DBL_MAX, FLT_EPSILON, etc.)
  • <errno.h> - Standard C error handling via errno macro representation
  • <stdint.h> - Standard fixed-width integer types (int8_t, uint32_t, etc.)
  • <stdbool.h> - Boolean utilities. (Note: Non-standard derived APIs start with an Uppercase letter)
  • <stddef.h> - Standard type definitions like size_t, ptrdiff_t, and NULL
  • <complex.h> - Complex number arithmetic and math functions (cabs, cexp, csqrt, etc.)
  • <inttypes.h> - Extended integer formatting and conversion functions (strtoimax, imaxabs, etc.)
  • <uchar.h> - Unicode and wide character utilities (char16_t, mbrtoc16, etc.)
  • <locale.h> - Localization utilities (setlocale, localeconv, Lconv)
  • <wchar.h> - Wide character string manipulation (wcslen, wcscpy, wchar_t, etc.)
  • <wctype.h> - Wide character classification (iswalpha, towlower, etc.)
  • <setjmp.h> - Non-local jumps and C-style exception handling (setjmp, longjmp, jmp_buf)
  • <dirent.h> - POSIX directory iteration (opendir, readdir, closedir, DIR, dirent)
  • <unistd.h>, <sys/stat.h>, <sys/types.h>, <fcntl.h> - POSIX standard interfaces (sleep, stat, getpid, etc.)
  • <sys/socket.h>, <netdb.h>, <netinet/in.h>, <arpa/inet.h> - POSIX sockets and networking API structure
  • <regex.h> - POSIX Regular Expressions (regcomp, regexec)
  • <getopt.h> - Command-line argument parsing (getopt, getopt_long)
  • <pthread.h> - POSIX Threads with Isolate message-passing abstractions (pthread_create)
  • <sys/time.h> - POSIX finer-grained time tracking (gettimeofday, timeval)
  • <sys/wait.h> - POSIX Process Control (wait, waitpid)
  • <sys/utsname.h> - POSIX System Identification (uname, utsname)
  • <termios.h> - POSIX Terminal I/O (tcgetattr, tcsetattr, termios)
  • <threads.h> - C11 Threads (thrd_create, mtx_lock, etc.)
  • <iso646.h> - Alternative operator spellings (Structural port)
  • <stdnoreturn.h> - noreturn definition
  • <stdalign.h> - Alignment stub definitions
  • <dlfcn.h> - Dynamic linking via FFI (dlopen, dlsym, etc.)
  • <fnmatch.h> - Filename matching (fnmatch)
  • <glob.h> - Pathname pattern expansion (glob, globfree)
  • <search.h> - Search algorithms (hsearch, tsearch, lsearch)
  • <syslog.h> - System logging (syslog, openlog, closelog, setlogmask)
  • <pwd.h>, <grp.h> - User and group database info (getpwuid, getpwnam, etc.)

"Why learn a new standard library when you already mastered the best one?"

Libraries

arpa_inet
assert
<assert.h> implementation for stdc
complex
<complex.h> implementation for stdc
ctype
<ctype.h> implementation for stdc
dirent
dlfcn
errno
<errno.h> implementation for stdc
fcntl
float
<float.h> implementation for stdc
fnmatch
getopt
<getopt.h> implementation for stdc
glob
grp
inttypes
<inttypes.h> implementation for stdc
iso646
<iso646.h> implementation for stdc
limits
<limits.h> implementation for stdc
locale
<locale.h> implementation for stdc
math
<math.h> implementation for stdc
netdb
netinet_in
pthread
pwd
regex
setjmp
signal
<signal.h> implementation for stdc
stdalign
<stdalign.h> implementation for stdc
stdarg
<stdarg.h> implementation for stdc
stdbool
<stdbool.h> implementation for stdc
stdc
A unified entrypoint for the stdc library.
stddef
<stddef.h> implementation for stdc
stdint
<stdint.h> implementation for stdc
stdio
<stdio.h> implementation for stdc
stdlib
<stdlib.h> implementation for stdc
stdnoreturn
<stdnoreturn.h> implementation for stdc
string
<string.h> implementation for stdc
sys_socket
sys_stat
sys_time
<sys/time.h> implementation for stdc
sys_types
sys_utsname
sys_wait
syslog
termios
threads
<threads.h> implementation for stdc
time
<time.h> implementation for stdc
uchar
<uchar.h> implementation for stdc
unistd
wchar
<wchar.h> implementation for stdc
wctype
<wctype.h> implementation for stdc