Scroll to navigation

stdlib.h(3avr) avr-libc stdlib.h(3avr)

NAME

stdlib.h

SYNOPSIS

Data Structures


struct div_t
struct ldiv_t

Macros


#define RAND_MAX 0x7FFF

Typedefs


typedef int(* __compar_fn_t) (const void *, const void *)

Functions


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)

Variables


size_t __malloc_margin
char * __malloc_heap_start
char * __malloc_heap_end

Non-standard (i.e. non-ISO C) functions.


#define RANDOM_MAX 0x7FFFFFFF
char * 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.

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 -lm option needs to be specified.
#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)

Macro Definition Documentation

#define RAND_MAX 0x7FFF

Highest number that can be generated by rand().

Typedef Documentation

typedef int(* __compar_fn_t) (const void *, const void *)

Comparision function type for qsort(), just for convenience.

Function Documentation

void abort (void)

The 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 integer i.

Note

The abs() and labs() functions are builtins of gcc.

int atoi (const char * __s)

The atoi() function converts the initial portion of the string pointed to by s to integer representation. In contrast to

(int)strtol(s, (char **)NULL, 10); 

this function does not detect overflow (errno is not changed and the result value is not predictable), uses smaller memory (flash and stack) and works more quickly.

long atol (const char * __s)

The atol() function converts the initial portion of the string pointed to by s to long integer representation. In contrast to

strtol(s, (char **)NULL, 10); 

this function does not detect overflow (errno is not changed and the result value is not predictable), uses smaller memory (flash and stack) and works more quickly.

void* bsearch (const void * __key, const void * __base, size_t __nmemb, size_t __size, int(*)(const void *, const void *) __compar)

The bsearch() function searches an array of nmemb objects, the initial member of which is pointed to by base, for a member that matches the object pointed to by key. The size of each member of the array is specified by size.

The contents of the array should be in ascending sorted order according to the comparison function referenced by compar. 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() function returns a pointer to a matching member of the array, or a null pointer if no match is found. If two members compare as equal, which member is matched is unspecified.

void* calloc (size_t __nele, size_t __size)

Allocate nele elements of size each. Identical to calling malloc() using nele * size as argument, except the allocated memory will be cleared 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 and rem.

void exit (int __status)

The 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.

long labs (long __i)

The labs() function computes the absolute value of the long integer i.

Note

The abs() and labs() functions are builtins of gcc.

ldiv_t ldiv (long __num, long __denom)

The ldiv() 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.

void* malloc (size_t __size)

The malloc() function allocates 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() usage for implementation details.

void qsort (void * __base, size_t __nmemb, size_t __size, __compar_fn_t __compar)

The qsort() function is a modified partition-exchange sort, or quicksort.

The qsort() function sorts an array of nmemb objects, the initial member of which is pointed to by base. The size of each object is specified by size. 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 to the objects being compared.

The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

int rand (void)

The rand() function computes a sequence of pseudo-random integers in the range of 0 to RAND_MAX (as defined by the header file <stdlib.h>).

The srand() 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 srand() with the same seed value.

If no seed value is provided, the functions are automatically seeded with a value of 1.

In compliance with the C standard, these functions operate on int arguments. Since the underlying algorithm already 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 * __ctx)

Variant of rand() 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 realloc() function tries to change the size of the region allocated at 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 acceptable to pass ptr as NULL, in which case realloc() will behave identical to malloc().

If the new memory cannot be allocated, realloc() returns NULL, and the region at ptr will not be changed.

void srand (unsigned int __seed)

Pseudo-random number generator seeding; see rand().

double strtod (const char * nptr, char ** endptr)

The strtod() function converts the initial 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 strtod() function returns the converted value, if any.

If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.

If no conversion is performed, zero is returned and the value of nptr is stored in the location referenced by endptr.

If the correct value would cause overflow, plus or minus INFINITY 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 (const char * __nptr, char ** __endptr, int __base)

The strtol() function converts the string in nptr to a 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 '-' 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 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' 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 original value of nptr in endptr. (Thus, if *nptr is not '\0' but **endptr is '\0' on return, the entire string was valid.)

The strtol() 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, errno is set to ERANGE and the function return value is clamped to LONG_MIN or LONG_MAX, respectively.

unsigned long strtoul (const char * __nptr, 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 '-' 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 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' representing 35.)

If endptr is not NULL, strtoul() stores the address of the first invalid character in *endptr. If there were no digits at all, however, strtoul() stores the original value of nptr in endptr. (Thus, if *nptr is not '\0' but **endptr is '\0' on return, the entire string was valid.)

The strtoul() function return either the result of the conversion or, if there was a leading minus sign, the negation of the result of the conversion, unless the original (non-negated) value would overflow; in the latter case, strtoul() returns ULONG_MAX, and errno is set to ERANGE. If no conversion could be performed, 0 is returned.

Variable Documentation

char* __malloc_heap_end [extern]

malloc() tunable.

char* __malloc_heap_start [extern]

malloc() tunable.

size_t __malloc_margin [extern]

malloc() tunable.

Author

Generated automatically by Doxygen for avr-libc from the source code.

Fri Jan 7 2022 Version 2.0.0