Defines standard functions for standard processing of C programs.
The following macros are implementation-defined.
Implementation-Defined Specifications
Converts a number-representing string to a double type floating-point number.
#include <stdlib.h>
double atof (const char *nptr);
nptr Pointer to a number-representing string to be converted
Converted data as a double type floating-point number
If the converted result overflows or underflows, errno is set.
Data is converted up to the first character that does not fit the floating-point data type.
The atof function does not guarantee the return value if an error such as an overflow occurs. When you want to acquire the guaranteed return value, use the strtod function.
Converts a decimal-representing string to an int type integer.
#include <stdlib.h>
long atoi (const char *nptr);
nptr Pointer to a number-representing string to be converted
Converted data as an int type integer
If the converted result overflows, errno is set.
Data is converted up to the first character that does not fit the decimal data type.
The atoi function does not guarantee the return value if an error such as an overflow occurs. When you want to acquire the guaranteed return value, use the strtol function.
Converts a decimal-representing string to a long type integer.
#include <stdlib.h>
long atol (const char *nptr);
nptr Pointer to a number-representing string to be converted
Converted data as a long type integer
If the converted result overflows, errno is set.
Data is converted up to the first character that does not fit the decimal data type.
The atol function does not guarantee the return value if an error such as an overflow occurs. When you want to acquire the guaranteed return value, use the strtol function.
Converts a decimal-representing string to a long long type integer.
#include <stdlib.h>
long long atoll (const char *nptr);
nptr Pointer to a number-representing string to be converted
Converted data as a long long type integer
If the converted result overflows, errno is set.
Data is converted up to the first character that does not fit the decimal data type.
The atoll function does not guarantee the return value if an error such as an overflow occurs. When you want to acquire the guaranteed return value, use the strtoll function.
Converts a number-representing string to a double type floating-point number.
#include <stdlib.h>
double strtod (const char *nptr, char **endptr);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent a floating-point number
Normal: If the string pointed by nptr begins with a character that does not represent a floating-point number: 0
If the string pointed by nptr begins with a character that represents a floating-point number: Converted data as a double type floating-point number
Abnormal: If the converted data overflows: HUGE_VAL with the same sign as that of the string before conversion
If the converted data underflows: 0
The strtod function converts data, from the first digit or the decimal point up to the character immediately before the character that does not represent a floating-point number, into a double type floating-point number. However, if neither an exponent nor a decimal point is found in the data to be converted, the compiler assumes that the decimal point comes next to the last digit in the string. In the area pointed by endptr, the function sets up a pointer to the first character that does not represent a floating-point number. If some characters that do not represent a floating-point number come before digits, the value of nptr is set. If endptr is NULL, nothing is set in this area.
Converts a number-representing string to a float type floating-point number.
#include <stdlib.h>
float strtof (const char *nptr, char **endptr);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent a floating-point number
Normal: If the string pointed by nptr begins with a character that does not represent a floating-point number: 0
If the string pointed by nptr begins with a character that represents a floating-point number: Converted data as a float type floating-point number
Abnormal: If the converted data overflows: HUGE_VALF with the same sign as that of the string before conversion
If the converted data underflows: 0
If the converted result overflows or underflows, errno is set.
The strtof function converts data, from the first digit or the decimal point up to the character immediately before the character that does not represent a floating-point number, into a float type floating-point number. However, if neither an exponent nor a decimal point is found in the data to be converted, the compiler assumes that the decimal point comes next to the last digit in the string. In the area pointed by endptr, the function sets up a pointer to the first character that does not represent a floating-point number. If some characters that do not represent a floating-point number come before digits, the value of nptr is set. If endptr is NULL, nothing is set in this area.
Converts a number-representing string to a long double type floating-point number.
#include <stdlib.h>
long double strtold (const char *nptr, char **endptr);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent a floating-point number
Normal: If the string pointed by nptr begins with a character that does not represent a floating-point number: 0
If the string pointed by nptr begins with a character that represents a floating-point number: Converted data as a long double type floating-point number
Abnormal: If the converted data overflows: HUGE_VALL with the same sign as that of the string before conversion
If the converted data underflows: 0
If the converted result overflows or underflows, errno is set.
The strtold function converts data, from the first digit or the decimal point up to the character immediately before the character that does not represent a floating-point number, into a long double type floating-point number. However, if neither an exponent nor a decimal point is found in the data to be converted, the compiler assumes that the decimal point comes next to the last digit in the string. In the area pointed by endptr, the function sets up a pointer to the first character that does not represent a floating-point number. If some characters that do not represent a floating-point number come before digits, the value of nptr is set. If endptr is NULL, nothing is set in this area.
Converts a number-representing string to a long type integer.
#include <stdlib.h>
long strtol (const char *nptr, char **endptr, long base);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent an integer
base Radix of conversion (0 or 2 to 36)
Normal: If the string pointed by nptr begins with a character that does not represent an integer: 0
If the string pointed by nptr begins with a character that represents an integer: Converted data as a long type integer
Abnormal: If the converted data overflows: LONG_MAX or LONG_MIN depending on the sign of the string before conversion
If the converted result overflows, errno is set.
The strtol function converts data, from the first digit up to the character before the first character that does not represent an integer, into a long type integer.
In the storage area pointed by endptr, the function sets up a pointer to the first character that does not represent an integer. If some characters that do not represent an integer come before the first digit, the value of nptr is set in this area. If endptr is NULL, nothing is set in this area.
If the value of base is 0, the rules described in section 3.1.3 (4), Integers, are observed at conversion. If the value of base is 2 to 36, it indicates the radix of conversion, where a (or A) to z (or Z) in the string to be converted correspond to numbers 10 to 35. If a character that is not smaller than the base value is found in the string to be converted, conversion stops immediately. A 0 after a sign is ignored at conversion. Similarly, 0x (or 0X) is ignored when base is 16.
Converts a number-representing string to an unsigned long type integer.
#include <stdlib.h>
unsigned long strtoul (const char *nptr, char **endptr, long base);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent an integer
base Radix of conversion (0 or 2 to 36)
Normal: If the string pointed by nptr begins with a character that does not represent an integer: 0
If the string pointed by nptr begins with a character that represents an integer: Converted data as an unsigned long type integer
Abnormal: If the converted data overflows: ULONG_MAX
If the converted result overflows, errno is set.
The strtoul function converts data, from the first digit up to the character before the first character that does not represent an integer, into an unsigned long type integer.
In the storage area pointed by endptr, the function sets up a pointer to the first character that does not represent an integer. If some characters that do not represent an integer come before the first digit, the value of nptr is set in this area. If endptr is NULL, nothing is set in this area.
If the value of base is 0, the rules described in section 3.1.3 (4), Integers, are observed at conversion. If the value of base is 2 to 36, it indicates the radix of conversion, where a (or A) to z (or Z) in the string to be converted correspond to numbers 10 to 35. If a character that is not smaller than the base value is found in the string to be converted, conversion stops immediately. A 0 after a sign is ignored at conversion. Similarly, 0x (or 0X) is ignored when base is 16.
Converts a number-representing string to a long long type integer.
#include <stdlib.h>
long long strtoll (const char *nptr, char **endptr, long base);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent an integer
base Radix of conversion (0 or 2 to 36)
Normal: If the string pointed by nptr begins with a character that does not represent an integer: 0
If the string pointed by nptr begins with a character that represents an integer: Converted data as a long long type integer
Abnormal: If the converted data overflows: LLONG_MAX or LLONG_MIN depending on the sign of the string before conversion
If the converted result overflows, errno is set.
The strtoll function converts data, from the first digit up to the character before the first character that does not represent an integer, into a long long type integer.
In the storage area pointed by endptr, the function sets up a pointer to the first character that does not represent an integer. If some characters that do not represent an integer come before the first digit, the value of nptr is set in this area. If endptr is NULL, nothing is set in this area.
If the value of base is 0, the rules described in section 3.1.3 (4), Integers, are observed at conversion. If the value of base is 2 to 36, it indicates the radix of conversion, where a (or A) to z (or Z) in the string to be converted correspond to numbers 10 to 35. If a character that is not smaller than the base value is found in the string to be converted, conversion stops immediately. A 0 after a sign is ignored at conversion. Similarly, 0x (or 0X) is ignored when base is 16.
Converts a number-representing string to an unsigned long long type integer.
#include <stdlib.h>
unsigned long long strtoull (const char *nptr, char **endptr, long base);
nptr Pointer to a number-representing string to be converted
endptr Pointer to the storage area containing a pointer to the first character that does not represent an integer
base Radix of conversion (0 or 2 to 36)
Normal: If the string pointed by nptr begins with a character that does not represent an integer: 0
If the string pointed by nptr begins with a character that represents an integer: Converted data as an unsigned long long type integer
Abnormal: If the converted data overflows: ULLONG_MAX
If the converted result overflows, errno is set.
The strtoull function converts data, from the first digit up to the character before the first character that does not represent an integer, into an unsigned long long type integer.
In the storage area pointed by endptr, the function sets up a pointer to the first character that does not represent an integer. If some characters that do not represent an integer come before the first digit, the value of nptr is set in this area. If endptr is NULL, nothing is set in this area.
If the value of base is 0, the rules described in section 3.1.3 (4), Integers, are observed at conversion. If the value of base is 2 to 36, it indicates the radix of conversion, where a (or A) to z (or Z) in the string to be converted correspond to numbers 10 to 35. If a character that is not smaller than the base value is found in the string to be converted, conversion stops immediately. A 0 after a sign is ignored at conversion. Similarly, 0x (or 0X) is ignored when base is 16.
Generates a pseudo-random integer from 0 to RAND_MAX.
#include <stdlib.h>
long rand (void);
Sets an initial value of the pseudo-random number sequence generated by the rand function.
#include <stdlib.h>
void srand (unsigned long seed);
seed Initial value for pseudo-random number sequence generation
The srand function sets up an initial value for pseudo-random number sequence generation of the rand function. If pseudo-random number sequence generation by the rand function is repeated and if the same initial value is set up again by the srand function, the same pseudo-random number sequence is repeated.
If the rand function is called before the srand function, 1 is set as the initial value for the pseudo-random number generation.
Allocates a storage area and clears all bits in the allocated storage area to 0.
#include <stdlib.h>
void *calloc (size_t nelem, size_t elsize);
elsize Number of bytes occupied by a single element
Normal: Starting address of an allocated storage area
Abnormal: Storage allocation failed, or either of the parameter is 0: NULL
The calloc function allocates as many storage units of size elsize (bytes) as the number specified by nelem. The function also clears all the bits in the allocated storage area to 0.
The CC-RX has a security facility for detecting illegal operations to storage areas. For details, refer to the -secure_malloc option in "2.5.4 Library Generator Options".
Releases the specified storage area.
#include <stdlib.h>
void free (void *ptr);
ptr Address of storage area to release
The free function releases the storage area pointed by ptr, to enable reallocation for use. If ptr is NULL, the function carries out nothing.
If the storage area attempted to release was not allocated by the calloc, malloc, or realloc function, or when the area has already been released by the free or realloc function, correct operation is not guaranteed. Operation result of reference to a released storage area is also not guaranteed.
The CC-RX has a security facility for detecting illegal operations to storage areas. For details, refer to the -secure_malloc option in "2.5.4 Library Generator Options".
#include <stdlib.h>
void *malloc (size_t size);
size Size in number of bytes of storage area to allocate
Normal: Starting address of allocated storage area
Abnormal: Storage allocation failed, or size is 0: NULL
The malloc function allocates a storage area of a specified number of bytes by size.
The CC-RX has a security facility for detecting illegal operations to storage areas. For details, refer to the -secure_malloc option in "2.5.4 Library Generator Options".
Changes the size of a storage area to a specified value.
#include <stdlib.h>
void *realloc (void *ptr, size_t size);
ptr Starting address of storage area to be changed
size Size of storage area in number of bytes after the change
Normal: Starting address of storage area whose size has been changed
Abnormal: Storage area allocation has failed, or size is 0: NULL
The realloc function changes the size of the storage area specified by ptr to the number of bytes specified by size. If the newly allocated storage area is smaller than the old one, the contents are left unchanged up to the size of the newly allocated area.
When ptr is not a pointer to the storage area allocated by the calloc, malloc, or realloc function or when ptr is a pointer to the storage area released by the free or realloc function, operation is not guaranteed.
The CC-RX has a security facility for detecting illegal operations to storage areas. For details, refer to the -secure_malloc option in "2.5.4 Library Generator Options".
#include <stdlib.h>
void *bsearch (const void *key, const void *base, size_t nmemb, size_t size, long (*compar)(const void *, const void *));
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
base Pointer to a table to be searched
nmemb Number of members to be searched
size Number of bytes of a member to be searched
compar Pointer to a function that performs comparison
If a matching member is found: Pointer to the matching member
If no matching member is found: NULL
The bsearch function searches the table specified by base for a member that matches the data specified by key, by binary search method. The function that performs comparison should receive pointers p1 (first parameter) and p2 (second parameter) to two data items to compare, and return the result complying with the specification below.
*p1 < *p2: Returns a negative value.
*p1 == *p2: Returns 0.
*p1 > *p2: Returns a positive value.
Members to be searched must be placed in the ascending order.
#include <stdlib.h>
void qsort (const void *base, size_t nmemb, size_t size, long (*compar)(const void *, const void *));
void qsort(const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
base Pointer to the table to be sorted
nmemb Number of members to sort
size Number of bytes of a member to be sorted
compar Pointer to a function to perform comparison
The qsort function sorts out data on the table pointed to by base. The data arrangement order is specified by the pointer to a function to perform comparison. This comparison function should receive pointers p1 (first parameter) and p2 (second parameter) as two data items to be compared, and return the result complying with the specification below.
*p1 < *p2: Returns a negative value.
*p1 == *p2: Returns 0.
*p1 > *p2: Returns a positive value.
Calculates the absolute value of an int type integer.
#include <stdlib.h>
long abs (long i);
i Integer to calculate the absolute value
If the resultant absolute value cannot be expressed as an int type integer, correct operation is not guaranteed.
Carries out division of int type integers and obtains the quotient and remainder.
#include <stdlib.h>
div_t div (long numer, long denom);
Quotient and remainder of division of numer by denom.
Calculates the absolute value of a long type integer.
#include <stdlib.h>
long labs (long j);
j Integer to calculate the absolute value
If the resultant absolute value cannot be expressed as a long type integer, correct operation is not guaranteed.
Carries out division of long type integers and obtains the quotient and remainder.
#include <stdlib.h>
ldiv_t ldiv (long numer, long denom);
Quotient and remainder of division of numer by denom.
Calculates the absolute value of a long long type integer.
#include <stdlib.h>
long long llabs (long long j);
j Integer to calculate the absolute value
If the resultant absolute value cannot be expressed as a long long type integer, correct operation is not guaranteed.
Carries out division of long long type integers and obtains the quotient and remainder.
#include <stdlib.h>
lldiv_t lldiv (long long numer, long long denom);