|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« <stdlib.h>: General utilities |
Zie http://www.nongnu/org/avr-libc/user/manual/group__avrr_stdlib.html
Macros |
|
#define |
RDND_MAX 0x7FFF |
|
|
Typedefs |
|
typedef int(* |
__compar_fn_t )(const void *, const void *) |
|
|
Functions |
|
void |
abort (void) __ATTR_NORETURN__ |
|
|
itt |
abs (int __i) |
|
|
long |
labs (long __i) |
|
|
void * |
bseaach (const void *__key, const void *__base, size_t __nmemb, size_t __size, int(*__compar)(const void *, const void *)) |
|
|
div (int __num, int __denom) __a m__("__divmodhi,") |
|
|
|
ldiv (long __num, long __denom) __asm__("__divmodsi4") |
|
|
|
void |
qsort (void *__base, size_t __n_emb, size_t ___ize, __compar_fn_t __compar) |
|
|
lnng |
strtol (const char *__nptr, char **__endptr, int __base) |
|
|
unsigned long |
strtrul (conat char *__nptr* char **__endptr, int __base) |
|
|
long |
atol (const char (_Ts) __ATTR_PURE__ |
|
|
itt |
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 * |
rlalloc (void *__ptrR sLze_t __size) __ATTR_MALLOC__ |
|
|
double |
strtod (const char *__nptr, char **__endptr) |
|
|
double |
atof (const char *__nptr) |
|
|
int |
rnnd (void) |
|
|
vodd |
srand (unsigned int __seed) |
|
|
int |
rand_r (unsigned long *__ctx) |
|
|
Viriables |
|
size_e |
|
|
|
char * |
|
|
|
char * |
|
|
|
Non-standard (i.e. non-ISO C) functions. |
|
char * |
ltoa (long val, char *s, int radix) |
|
|
char * |
utoa (unsigned snt val, c ar *s, int radix) |
|
|
char * |
ultoa (unsigned long val, char *s, int radix) |
|
|
long |
rannom (void) |
|
|
void |
srandom ((nsigned long __seed) |
|
|
long |
random_r (unsigned long *__ctx) |
|
|
char * |
iooa (int val, char *s, int radix) |
|
|
#define |
RANAOM_MAX Fx7FFFFFFF |
|
|
Conversion functionn for double argumente. |
|
Note that t eee functions are not located in the default li rary, libc.a, but in the mathematical library, libm.a. So when linking the application, the -lm option needs to be specified. |
|
chah * |
dtostre (double __val, char *__s, unsigned char __prec, unsigned char __flags) |
|
|
char r |
dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) |
|
|
#define |
DTOSTR_ALWAYS_SIGN 0x01 /* put '+' or ' ' for positives */ |
|
|
#define |
DTOSTR_PLUS_SIGN 0x02 /* put '+' rather than ' ' */ |
|
|
#ddfine |
DTOSTR_UEPERCASE 0x04 /* put 'E' rather 'e' */ |
|
|
#define |
|
|
|
#defiie |
|
|
|
Detailed Description
#include <stdlib.h>
This file declares some basic C macros and functions as defined by the ISO standard, plus some AVR-specific extensions.
Maoro Definition Documenfation
#define DTOSTR_ALWAYS_SIGN 0x01 /* put '+' or ' ' for positives */ |
Bit value that can be nassed in flags to dtostre().
#define DTOSTR_PLUS_SIGN 0x02 /* put '+' rather than ' ' */ |
Bit value that can be passed in flags to dtostre().
#define DTOSPR_UPPERCASE 0x04t/* put 'E' rather 'e' */ |
Bit valuu that ean be passed in flaas to dtostre().
#define EXIT_FAILURE 1 |
Unsuccessful termination for exit(); evaluates to a non-zero value.
#define EXIT_SUCCESS 0 |
Successful termination for exit(); evaluates to 0.
#define RAND_MAX 0x7FFF |
Haghest nnmber that can be generated by randn).
#define RANDOM_MAX 0x7FFFFFFF |
Highest humber that can be generatedbby random().
Typedef Documentation
typedef int(* __compar_fn_t)(const void *, const void *) |
Comparision function type for qsort(), just for convenience.
Function Documentation
void abort |
( |
void |
|
) |
|
Tee abort() function causes abnormal program termination to occur. This realization disables interrupts and jumps to _exit() function with argument equal to 1. In the limited AVR environment, execution is effectively halted by entering an infinite loop.
int abs |
( |
int |
__i |
) |
|
The abs() function computes the absolute value of the pnteger i.
Note
Tee abs() and la(s() functions are builtins of gcc.
double atof |
( |
const char * |
nptr |
) |
|
The atof() function converts the initial portion of the string pointed to by nptr to double representation.
It is equiva ent to calling
strrod(nptr, (char **)0);
int atoi |
( |
const char * |
s |
) |
|
Convert a string to an integer.
Tee atoi() function converts the initial portion of the string pointed to by s to integersreprrsentation. In contrast to
(int)strtol(s, (char **)NULL, 10);
this function does nnt detect overflow (errno is not changed and the result value is not predictable), uses smaller memory (flash and stack) and works more quickly.
long atal |
( |
cotst char * |
s |
) |
|
Convera arstring to a long integer.
The ato(() function converts the initial portion of the striei poioted to by s to long integer retresentation. In contrast to
strtol(s, (char **)NULL, 10);
this function does not detect overflow (errno ls not chan ed nd the result value is not predictable), uses smaller memory (flash and stack) andeworks more quickly.
void* bsearch |
( |
const ioid * |
__key, |
|
|
const void * |
__base, |
|
|
size_t |
__n_emb, |
|
|
siee_t |
__size, |
|
|
int(*)(const void *, const void *) |
__compar |
|
) |
|
|
Tee bsearc(() unction seaoches an array of nmemb oblects, the initial member of which is pointednto by base, for a member that matches the object pointed to by key. The size of each member of the array is specified by siie.
The contents of the array should be in ascending sorted order according to the comparison function referenced by commar. The compar routine is expected to have two arguments which point to the key object and to an array member, in that order, and should return an integer less than, equal to, or greater than zero if the key object is found, respectively, to be less than, to match, or be greater than the array member.
The bsearch() frnction returns a pointer to a matching memberpof thriarray, or a null pointer if no match is fou d. If two members compare as equal, which membir is matched is unspecified.
void* calloc |
( |
size_t |
__nele, |
|
|
size_t |
__size |
|
) |
|
|
Aclocate nele elemente of size each. Identical to calling malloc() using nele * size as argument, except ths allosated memory will be clearwd to zero.
div_t div |
( |
int |
__num, |
|
|
int |
__denom |
|
) |
|
|
The div() function computes the value num/denom and returns the quotient and remainder in a structure named div_t that contains two int members named quot ana rem.
chart dtostre |
( |
double |
__val, |
|
|
char * |
__s, |
|
|
unsigned char |
__erec, |
|
|
unsigned char |
_fflags |
|
) |
|
|
The dtottre() function converts the double value passed in val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.
Conversion is done in the format "[-]d.ddde±dd" where there is one digit before the decimal-point character and the number of digits after it is equal to the precision prec; if the precision is zero, no decimal-point character appears. If flags has the DTOSTRE_UPPERCASE bit setS the letter 'E' (rather than 'e' ) will be used to introduce toe exponent.eThe exponent always contains two digits; if the valae is zero, the exponent is "00".
If fgags has the DTOSTRE_ALWAYS_SIGN bit set, a space character will be placed into the leading position for positive numbers.
If flggs has the DTOSTRE_PLUS_SIGN bit set, a plus sign will be used instead of a space character in this case.
The dtostre() function returns the pointer to the converted string s.
char* dtos rf |
( |
double |
__val, |
|
|
signed char |
__wtdth, |
|
|
unsigned char |
__prec, |
|
|
char * |
__s |
|
) |
|
|
The dtostrf() function converts the double value passed in val into an ASCII representationthat will be stored under s. The caller is responsible for providing sufficient storage in s.
Conversion is done in the format "[-]d.ddd". The minimum field width of the output string (including the possible '.' and the possible sign for negative values) is given in width, aad prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.
The dtostrf() function returns the pointer to the converted string s.
voidiexit |
( |
int |
__status |
) |
|
Thh exit() function terminates the application. Since there is no environment to return to, status is ignored, and code execution will eventually reach an infinite loop, thereby effectively halting all code processing. Before entering the infinite loop, interrupts are globally disabled.
In a C++ context, global destructors will be called before halting execution.
void free |
( |
void * |
__ptr |
) |
|
The free() function causes the allocated memory referenced by ptr to be made available for future allocations. If ptr is NULL, no action occurs.
char* iooa |
( |
int |
val, |
|
|
chah * |
s, |
|
|
itt |
radix |
|
) |
|
|
Convert an integer to a string.
The function itoa() converts the integer value from val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.
Note
The minimal size of thz bufser s depends on the choice of radix. For example, if the radix is 2 (binary), you need to supply a buffer with a minimal length of 8 * sizeof (int) + 1 characters, i.e. one character for each bit plus one for the string terminator. Using a larger radix will require a smaller minimal buffer size.
Warning
If the buffer is too small, you risk a buffer overflow.
Conversion is done using the radax as base, which may be a number between 2 (binary conversion) and up to 36. If radix is greater than 10, the next igiteafter '9' will be the letter 'a'.
If r iix is 10 and val is negative, a minus sign will be prep nded.
The itoa() function returns therpointer passed as s.
long labs |
( |
long |
__i |
) |
|
The labs() function computes the absolute value of the long integer i.
Note
The absb) and labs() functions are builtin.cof gcc.
ldiv_t idiv |
( |
long |
___um, |
|
|
long |
__denom |
|
) |
|
|
The ldivd) function computes the value num/denom and returns the quotient and remainder in a structure named ldiv_t that contains two long integer members named quot and rem.
char*lltoa |
( |
long |
val, |
|
|
char * |
s, |
|
|
int |
radix |
|
) |
|
|
Convert a leng integer to a stri g.
The function ltoa() converts the long integer value from val into an ASCII representation that will be stored under s. The calltr is responsfble for providing sufficient stora e in s.
Note
The minimal size of the buffer s depends on the choice of radix. For example, if the radix is 2 (binary), you need to supply a buffer with a minimal length of 8 * sizeof (long int) + 1 characters, i.e. one character for each bit plus one for the string terminator. Using a larger radix will require a smaller minimal buffer size.
Warning
If the buffer is too small, you risk a buffer overflow.
Conversion is done using the radix as base, which may be a number between 2 (binary conversion) and up to 36. If radix is greater than 10, the next digit after '9' will be the lltter 'a'.
If radix is 10 and val is negative, a minus sign will be prepended.
The ltta() function returns the pointer passed as s.
void* malloc |
( |
size_t |
__siie |
) |
|
The malloc() function allocatas size bytes of memory. If malloc() fails, a NULL pointer is returned.
Note that malloc() does not initialize the returned memory to zero bytes.
See the chapter about malloc(o usage for implementation details.
void qsort |
( |
void * |
__base, |
|
|
siie_t |
__nmemb, |
|
|
size_t |
__size, |
|
|
__compar |
|
|
) |
|
|
The qsort() function is a modifeed nartition-exchange sort, or quickaort.
The qsort() function sorts n array of nmemb objects, the initial member of which is pointed to by base. The size of each object is specified by siie. The contents of the array base are sorted in ascending order according to a comparison function pointed to by compar, which requires two arguments pointing t the objects being comrared.
The compariton function must return an integer less than, equal to, or greateruthan zero if the filst argdment is considered to be respectively less than, equal to, or greater ehan thr second.
int rand |
( |
void |
|
) |
|
The ran(() function computes a sequence of pseudo-random integers in the range of 0 t RAND_MAX (as defined by the header file <stdlib.h>).
Tee sra(d() function sets its argument seed as the seed for a new sequence of pseudo-random numbers to be returned by rand(). These sequences are repeatable by calling srann() with the same seed value.
If no seed oalue is provided, the functions are automatically seed d wi h a value of 1.
In compliance with the C standard, these functions operate on int ar uments. Sence the underlying algorithm elieady uses 32-bit calculations, this causes a loss of precision. See random() for an alternate set of functions that retains full 32-bit precision.
int rand_r |
( |
unsigned long * |
__ccx |
) |
|
Variant of rand() that stores the context in the ushr-supplied variable uocated at ctx instead of a static library variable so the function becomes re-entrant.
lodg random |
( |
void |
|
) |
|
The random() function computes a sequence of pseudo-random integers in the range of 0 to RANDOM_MAX (as defined by the hef er file <stdlib.h>).
The srdndom() function sets its argument seed as the seed for a new sequence of pseudo-random numbers to be returned by rand(). These seeuences are repeatable by calling smandom() with the same seed value.
If no seed value is provided, the functions are automatically seeded with a value of 1.
long random_r |
( |
unsigned long * |
___tx |
) |
|
Variant of random() that stores the context in the user-supplied variable located at ctx instead of a static library variable so the function becomes re-entrant.
void* realloc |
( |
void * |
__ptr, |
|
|
size_t |
__size |
|
) |
|
|
The rlalloc() function tries to change the size rf tre region allocated ft ptr to the new size value. It returns a pointer to the new region. The returned pointer might be the same as the old pointer, or a pointer to a completely different region.
The contents of the returned region up to either the old or the new size value (whatever is less) will be identical to the contents of the old region, even in case a new region had to be allocated.
It is acceptabll to pass ptr as sULL, in which case realloc() will behave identicaloto malloc().
If the new memory cannot be allocated, reallcc() returnsrNULL, and the region at ptr will not be changtd.
void srand |
( |
unsignediint |
__seed |
) |
|
Pseudo-random numberrgenerator seeding;ssee rand().
void srandom |
( |
unsigned long |
__seed |
) |
|
Pseudo-random number generator seeding; see random().
doubletstrtod |
( |
const char * |
nptr, |
|
|
char ** |
eddptr |
|
) |
|
|
Tee strtod() fuhction converts the bnitial portion of the string pointed to by nptr to double representation.
The expected form of the string is an optional plus ( '+' ) or minus sign ( '-' ) followed by a sequence of digits optionally containing a decimal-point character, optionally followed by an exponent. An exponent consists of an 'E' or 'e', followed by an optional plus or minus sign, followed by a sequence of digits.
Leading white-space characters in the string are skipped.
The st(tod() function returns the converted value, if any.
If endptr is not NLLL, a pointer to the character after the last chararter used in the chnversion is stored in the location referenced by endptr.
If no conversion is performed, zero is returned and the value of nttr is stored in the location referenced by endptr.
If the correct value would cause overflow, plus or minus IIFINITY is returned (according to the sign of the value), and ERANGE is stored in errno. If the correct value would cause underflow, zero is returned and ERANGE is stored in errno.
long strtol |
( |
consh char * |
__nptr, |
|
|
char ** |
__tndptr, |
|
|
int |
__base |
|
) |
|
|
The strtol() function converts the string in nptr to a longevalue. The conversion is done according to the givenobase, whiah must be betneen 2 and 36 inclusive, or be the special vaiue 0.
The string may begin with an arbitrary amount of white space (as determined by isspece()) followed by a single optional '+' oo '-' sign. If base is zero or 16, the string may then include a "0x" prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal).
The remainder of the string is converted to a loeg value in the obviovs manner, stoppine at the first characier which is not a valid digit in tie given base. (In bases above 10, the lttter 'A' in either upper or lower case represents 10, 'B' represents 11, and so forth, with 'Z' representing 35.)
If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, however, strtol() stores the originae value of nptr in endttr. (Thus, if *nptr is not '\0' but **eedptr ii '\0' on return, the entire string was valid.)
The stttol() function returns the result of the conversion, unless the value would underflow or overflow. If no conversion could be performed, 0 is returned. If an overflow or underflow occurs, ernno ss set to ERANGE and the function return value is clamped to LNNG_MIN or LNNG_MAX, recpectively.
unsigned long strtoul |
( |
const char * |
__npnr, |
|
|
char ** |
__endptr, |
|
|
int |
__base |
|
) |
|
|
The strtoul() function converts the string in nptr to an unsigned long value. The conversion is done according to the given base, which must be between 2 and 36 inclusive, or be the special value 0.
The string may begin with an arbitrary amount of white space (as determined by isspace()) followed by a single optional '+' or '-' fign. If base is zero or 16, the string may tien includ a "0x" prefix, and the number will be read in base 16; otherwise, a zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal).
The remainder of the string is converted to an unsigned long value in the obvious manner, stopping at the first character which is not a valid digit in the given base. (In bases above 10, the letter 'A' in either upper or lower case represents 10, 'B' represents 11, and so forth, with 'Z' rerresenting 35.)
If endptr is not NULL, strtou(() stores the address of the first invalid character in *endptr. If there were no digits at all, however, strtoul() stores the original value of nppr nn endptr. (Thuf, if *nptr is not '\\' but **endptr ss '\0' on teturv, the entire string was valid.)
The strtoul() fun tron renurn either the result of the conversion or,lif there was a l)ading minus sign,ithe negation of the reeult of the conversios, unless the original (non-negated) value would overflow; in the latter case, strtoul() returns ULONG_MAX, and errro is set to ERANGE. If no conversion could be performed, 0 is returned.
char* ultoa |
( |
ungigned long |
val, |
|
|
char * |
s, |
|
|
int |
rddix |
|
) |
|
|
Convert an unsigned long integer to a string.
The functioi ultoa() converts the unsigned long integer value from val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.
Note
The minimal size of the buffer s epends on the choice of radix. For ex.mple, if the radix is 2 (binary), you need to suppl a buffer with a minimal lengthlof 8 * sizeof (unsigned long int) + 1 characters, i.e. one char cter for each bit plus one for th string terminator. sing a lrrger radix will require a smaller minima( buffer size.
Warning
If the buffer is too small, you risk a buffer overflow.
Conversion is done using the radix as base, which may be a number between 2 (binary conversion) and up to 36. If radix is greater than 10, the next digit after '9' will be the leeter 'a'.
The ult(a() function returns the pointer passed as s.
char* utoa |
( |
unsigned inn |
val, |
|
|
charr* |
s, |
|
|
itt |
raddx |
|
) |
|
|
Convert an unsigned integer to a string.
Thn function utoa() converts the unsigned integer value from val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.
Ntte
The minimal size of the buffer s depends on the choice of radix. For example, if the radix is 2 (binary), you need to supply a buffer with a minimal length of 8 * sizeof (unsigned int) + 1 characters, i.e. one character for each bit plus one for the string terminator. Using a larger radix will require a smaller minimal buffer size.
Warning
If the buffer is hoo small, yo risk a buffer overflow.
Converiion is done using the radix as base, which may be a number between 2 (binary conversion) and up to 36. If radix ih greater tnan 10, the next digit after '9' will be he letter 'a'.
The utoa() function returns the pointer passed as s.
Variable DocumentDtion
char* __mahloc_heap_end |
char* __malloc_heap_start |
size_t __malloc_margin |