Difference between revisions of "cpp/header/cstdlib"
From cppreference.com
(fix typo) |
(+aligned_alloc, +whole synopsis (from n4606)) |
||
Line 35: | Line 35: | ||
{{dsc h2 | Memory management}} | {{dsc h2 | Memory management}} | ||
{{dsc fun | cpp/memory/c/malloc | allocates memory}} | {{dsc fun | cpp/memory/c/malloc | allocates memory}} | ||
+ | {{dsc fun | cpp/memory/c/aligned_alloc | allocates aligned memory|notes={{mark c++17}}}} | ||
{{dsc fun | cpp/memory/c/calloc | allocates and zeroes memory}} | {{dsc fun | cpp/memory/c/calloc | allocates and zeroes memory}} | ||
{{dsc fun | cpp/memory/c/realloc | expands previously allocated memory block}} | {{dsc fun | cpp/memory/c/realloc | expands previously allocated memory block}} | ||
Line 61: | Line 62: | ||
{{dsc inc | cpp/numeric/math/dsc div}} | {{dsc inc | cpp/numeric/math/dsc div}} | ||
{{dsc end}} | {{dsc end}} | ||
+ | |||
+ | ===Synopsis=== | ||
+ | {{source|1= | ||
+ | namespace std { | ||
+ | using size_t = /*implementation-defined*/; | ||
+ | using div_t = /*implementation-defined*/ ; | ||
+ | using ldiv_t = /*implementation-defined*/ ; | ||
+ | using lldiv_t = /*implementation-defined*/ ; | ||
+ | } | ||
+ | |||
+ | #define NULL /*implementation-defined*/ | ||
+ | #define EXIT_FAILURE /*implementation-defined*/ | ||
+ | #define EXIT_SUCCESS /*implementation-defined*/ | ||
+ | #define RAND_MAX /*implementation-defined*/ | ||
+ | #define MB_CUR_MAX /*implementation-defined*/ | ||
+ | |||
+ | namespace std { | ||
+ | // start and termination | ||
+ | [[noreturn]] void abort(); | ||
+ | int atexit(void (*func)()); | ||
+ | int at_quick_exit(void (*func)()); | ||
+ | [[noreturn]] void exit(int status); | ||
+ | [[noreturn]] void _Exit(int status); | ||
+ | [[noreturn]] void quick_exit(int status); | ||
+ | char* getenv(const char* name); | ||
+ | int system(const char* string); | ||
+ | |||
+ | // C library memory allocation | ||
+ | void* aligned_alloc(size_t alignment, size_t size); | ||
+ | void* calloc(size_t nmemb, size_t size); | ||
+ | void free(void* ptr); | ||
+ | void* malloc(size_t size); | ||
+ | void* realloc(void* ptr, size_t size); | ||
+ | double atof(const char* nptr); | ||
+ | int atoi(const char* nptr); | ||
+ | long int atol(const char* nptr); | ||
+ | long long int atoll(const char* nptr); | ||
+ | double strtod(const char* nptr, char** endptr); | ||
+ | float strtof(const char* nptr, char** endptr); | ||
+ | long double strtold(const char* nptr, char** endptr); | ||
+ | long int strtol(const char* nptr, char** endptr, int base); | ||
+ | long long int strtoll(const char* nptr, char** endptr, int base); | ||
+ | unsigned long int strtoul(const char* nptr, char** endptr, int base); | ||
+ | unsigned long long int strtoull(const char* nptr, char** endptr, int base); | ||
+ | |||
+ | // multibyte / wide string and character conversion functions | ||
+ | int mblen(const char* s, size_t n); | ||
+ | int mbtowc(wchar_t* pwc, const char* s, size_t n); | ||
+ | int wctomb(char* s, wchar_t wchar); | ||
+ | size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n); | ||
+ | size_t wcstombs(char* s, const wchar_t* pwcs, size_t n); | ||
+ | |||
+ | // C standard library algorithms | ||
+ | extern "C" void* bsearch(const void* key, const void* base, | ||
+ | size_t nmemb, size_t size, | ||
+ | int (*compar)(const void* , const void*)); | ||
+ | extern "C++" void* bsearch(const void* key, const void* base, | ||
+ | size_t nmemb, size_t size, | ||
+ | int (*compar)(const void* , const void*)); | ||
+ | extern "C" void qsort(void* base, size_t nmemb, size_t size, | ||
+ | int (*compar)(const void* , const void*)); | ||
+ | extern "C++" void qsort(void* base, size_t nmemb, size_t size, | ||
+ | int (*compar)(const void* , const void*)); | ||
+ | |||
+ | // low-quality random number generation | ||
+ | int rand(); | ||
+ | void srand(unsigned int seed); | ||
+ | |||
+ | // absolute values | ||
+ | int abs(int j); | ||
+ | long int abs(long int j); | ||
+ | long long int abs(long long int j); | ||
+ | float abs(float j); | ||
+ | double abs(double j); | ||
+ | long double abs(long double j); | ||
+ | long int labs(long int j); | ||
+ | long long int llabs(long long int j); | ||
+ | div_t div(int numer, int denom); | ||
+ | ldiv_t div(long int numer, long int denom); | ||
+ | lldiv_t div(long long int numer, long long int denom); | ||
+ | ldiv_t ldiv(long int numer, long int denom); | ||
+ | lldiv_t lldiv(long long int numer, long long int denom); | ||
+ | } | ||
+ | }} | ||
===See Also=== | ===See Also=== |
Revision as of 11:26, 9 November 2016
This header was originally in the C standard library as <stdlib.h>.
This header provides miscellaneous utilities. Symbols defined here are used by several library components.
Contents |
Macro constants
indicates program execution status (macro constant) | |
MB_CUR_MAX |
maximum number of bytes in a multibyte character with the current locale (macro constant) |
implementation-defined null pointer constant (macro constant) | |
maximum possible value generated by std::rand (macro constant) |
Types
structure type, returned by std::div (typedef) | |
structure type, returned by std::ldiv (typedef) | |
(C++11) |
structure type, returned by std::lldiv (typedef) |
unsigned integer type returned by the sizeof operator (typedef) |
Functions
Process control | |
causes abnormal program termination (without cleaning up) (function) | |
causes normal program termination with cleaning up (function) | |
(C++11) |
causes quick program termination without completely cleaning up (function) |
(C++11) |
causes normal program termination without cleaning up (function) |
registers a function to be called on std::exit() invocation (function) | |
(C++11) |
registers a function to be called on std::quick_exit invocation (function) |
calls the host environment's command processor (function) | |
access to the list of environment variables (function) | |
Memory management | |
allocates memory (function) | |
(C++17) |
allocates aligned memory (function) |
allocates and zeroes memory (function) | |
expands previously allocated memory block (function) | |
deallocates previously allocated memory (function) | |
Numeric string conversion | |
converts a byte string to a floating point value (function) | |
(C++11) |
converts a byte string to an integer value (function) |
(C++11) |
converts a byte string to an integer value (function) |
(C++11) |
converts a byte string to an unsigned integer value (function) |
converts a byte string to a floating-point value (function) | |
Wide string manipulation | |
returns the number of bytes in the next multibyte character (function) | |
converts the next multibyte character to wide character (function) | |
converts a wide character to its multibyte representation (function) | |
converts a narrow multibyte character string to wide string (function) | |
converts a wide string to narrow multibyte character string (function) | |
Miscellaneous algorithms and math | |
generates a pseudo-random number (function) | |
seeds pseudo-random number generator (function) | |
sorts a range of elements with unspecified type (function) | |
searches an array for an element of unspecified type (function) | |
(C++11) |
computes absolute value of an integral value (|x|) (function) |
(C++11) |
computes quotient and remainder of integer division (function) |
Synopsis
namespace std { using size_t = /*implementation-defined*/; using div_t = /*implementation-defined*/ ; using ldiv_t = /*implementation-defined*/ ; using lldiv_t = /*implementation-defined*/ ; } #define NULL /*implementation-defined*/ #define EXIT_FAILURE /*implementation-defined*/ #define EXIT_SUCCESS /*implementation-defined*/ #define RAND_MAX /*implementation-defined*/ #define MB_CUR_MAX /*implementation-defined*/ namespace std { // start and termination [[noreturn]] void abort(); int atexit(void (*func)()); int at_quick_exit(void (*func)()); [[noreturn]] void exit(int status); [[noreturn]] void _Exit(int status); [[noreturn]] void quick_exit(int status); char* getenv(const char* name); int system(const char* string); // C library memory allocation void* aligned_alloc(size_t alignment, size_t size); void* calloc(size_t nmemb, size_t size); void free(void* ptr); void* malloc(size_t size); void* realloc(void* ptr, size_t size); double atof(const char* nptr); int atoi(const char* nptr); long int atol(const char* nptr); long long int atoll(const char* nptr); double strtod(const char* nptr, char** endptr); float strtof(const char* nptr, char** endptr); long double strtold(const char* nptr, char** endptr); long int strtol(const char* nptr, char** endptr, int base); long long int strtoll(const char* nptr, char** endptr, int base); unsigned long int strtoul(const char* nptr, char** endptr, int base); unsigned long long int strtoull(const char* nptr, char** endptr, int base); // multibyte / wide string and character conversion functions int mblen(const char* s, size_t n); int mbtowc(wchar_t* pwc, const char* s, size_t n); int wctomb(char* s, wchar_t wchar); size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n); size_t wcstombs(char* s, const wchar_t* pwcs, size_t n); // C standard library algorithms extern "C" void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void* , const void*)); extern "C++" void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void* , const void*)); extern "C" void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void* , const void*)); extern "C++" void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void* , const void*)); // low-quality random number generation int rand(); void srand(unsigned int seed); // absolute values int abs(int j); long int abs(long int j); long long int abs(long long int j); float abs(float j); double abs(double j); long double abs(long double j); long int labs(long int j); long long int llabs(long long int j); div_t div(int numer, int denom); ldiv_t div(long int numer, long int denom); lldiv_t div(long long int numer, long long int denom); ldiv_t ldiv(long int numer, long int denom); lldiv_t lldiv(long long int numer, long long int denom); }