stdlib.h(3)
π stdlib.h π
okay bestie, sit DOWN because we're doing stdlib.h from avr-libc today and it's lowkey the blueprint of every C program you've ever loved. this is the header that hands you memory, math-ish number crunching, sorting, searching, and the iconic exit(). it's giving backstage pass to the whole runtime. let's get into it β¨
πΈ NAME πΈ
stdlib.h β the standard library header, bestie. that's it, that's the name π
β¨ SYNOPSIS β¨
π Data Structures
the little structs that hold your division results, so you get the quotient AND the remainder in one gorgeous package:
struct div_tstruct ldiv_t
π Macros
#define RAND_MAX 0x7FFF
that's your ceiling for rand(), periodt.
π¦ Typedefs
typedef int(* __compar_fn_t) (const void *, const void *)
this is the function-pointer type you hand to qsort() and bsearch() so they know how to compare your stuff. two const void * args, returns an int. iconic signature tbh.
π Functions
here's the whole roster, no cap, nothing skipped:
void abort (void) __ATTR_NORETURN__
int abs (int __i)
long labs (long __i)
void * bsearch (const void *__key, const void *__base, size_t __nmemb,
size_t __size, int(*__compar)(const void *, const void *))
div_t div (int __num, int __denom) __asm__('__divmodhi4')
ldiv_t ldiv (long __num, long __denom) __asm__('__divmodsi4')
void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t
__compar)
long strtol (const char *__nptr, char **__endptr, int __base)
unsigned long strtoul (const char *__nptr, char **__endptr, int __base)
long atol (const char *__s) __ATTR_PURE__
int atoi (const char *__s) __ATTR_PURE__
void exit (int __status) __ATTR_NORETURN__
void * malloc (size_t __size) __ATTR_MALLOC__
void free (void *__ptr)
void * calloc (size_t __nele, size_t __size) __ATTR_MALLOC__
void * realloc (void *__ptr, size_t __size) __ATTR_MALLOC__
double strtod (const char *__nptr, char **__endptr)
double atof (const char *__nptr)
int rand (void)
void srand (unsigned int __seed)
int rand_r (unsigned long *__ctx)
quick vibes check on those attributes:__ATTR_NORETURN__means the function never comes back (it's leaving the party and not saying bye),__ATTR_MALLOC__and__ATTR_PURE__are compiler hints, and__asm__('__divmodhi4')/__asm__('__divmodsi4')are the literal assembly symbol names. copy those exactly, bestie, character for character. π
π Variables
the malloc internals you can poke at:
size_t __malloc_marginchar * __malloc_heap_startchar * __malloc_heap_end
π Non-standard (i.e. non-ISO C) functions.
these are the bonus tracks β not ISO C, but avr-libc said "and for my next trick":
#define RANDOM_MAX 0x7FFFFFFFchar * itoa (int val, char *s, int radix)char * ltoa (long val, char *s, int radix)char * utoa (unsigned int val, char *s, int radix)char * ultoa (unsigned long val, char *s, int radix)long random (void)void srandom (unsigned long __seed)long random_r (unsigned long *__ctx)
π§ Conversion functions for double arguments.
okay bestie this part is IMPORTANT, read it twice:
Note that these functions are not located in the default library,libc.a, but in the mathematical library,libm.a. So when linking the application, the-lmoption needs to be specified.
translation: if you forget -lm you're gonna get link errors and cry. don't do that to yourself. π
#define DTOSTR_ALWAYS_SIGN 0x01 /* put '+' or ' ' for positives
*/
#define DTOSTR_PLUS_SIGN 0x02 /* put '+' rather than ' ' */
#define DTOSTR_UPPERCASE 0x04 /* put 'E' rather 'e' */
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
char * dtostre (double __val, char *__s, unsigned char __prec, unsigned
char __flags)
char * dtostrf (double __val, signed char __width, unsigned char __prec,
char *__s)
those three DTOSTR_* flags are bit flags, so you OR them together like the little legends they are. β¨
π«Ά Author
Generated automatically by Doxygen for avr-libc from the source code.
and that's the whole page, bestie!! π it was written by Doxygen (the auto-generation queen) for avr-libc, and this specific glow-up is Version 2.1.0, dated Sat Jan 29 2022. go forth and malloc responsibly, mwah π
π
π¦ where this page comes from
- fedora 43: avr-libc 2.2.1-3.fc43 Β· BSD-3-Clause
- fedora 44: avr-libc 2.2.1-5.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: avr-libc 2.1.0-bp160.1.33 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms