ANSI C Stdlib Library
The mikroC PRO for 8051 provides a set of standard ANSI C library functions of general utility.
Important :
- Not all of the standard functions have been included.
- The functions have been mostly implemented according to the ANSI C standard, but certain functions have been modified in order to facilitate 8051 programming. Be sure to skim through the description before using standard C functions.
Library Functions
abs
| Prototype |
int abs(int a); |
|---|---|
| Description |
Function returns the absolute (i.e. positive) value of |
| Example |
result = abs(-12); // result = 12 |
atof
| Prototype |
double atof(char *s); |
|---|---|
| Description |
Function converts the input string |
| Example |
doub = atof("-1.23"); // doub = -1.23
|
atoi
| Prototype |
int atoi(char *s); |
|---|---|
| Description |
Function converts the input string |
| Example |
result = atoi("32000"); // result = 32000
|
atol
| Prototype |
long atol(char *s); |
|---|---|
| Description |
Function converts the input string |
| Example |
result = atol("-32560"); // result = -32560
|
div
| Prototype |
div_t div(int number, int denom); |
|---|---|
| Description |
Function computes the result of division of the numerator |
| Example |
dt = div(1234,100); |
ldiv
| Prototype |
ldiv_t ldiv(long number, long denom); |
|---|---|
| Description |
Function is similar to the div function, except that the arguments and result structure members all have type Function computes the result of division of the numerator |
| Example |
dl = ldiv(-123456, 1000); |
uldiv
| Prototype |
uldiv_t uldiv(unsigned long number, unsigned long denom); |
|---|---|
| Description |
Function is similar to the div function, except that the arguments and result structure members all have type Function computes the result of division of the numerator |
| Example |
dul = uldiv(123456,1000); |
labs
| Prototype |
long labs(long x); |
|---|---|
| Description |
Function returns the absolute (i.e. positive) value of long integer |
| Example |
result = labs(-2147483647); |
max
| Prototype |
int max(int a, int b); |
|---|---|
| Description |
Function returns greater of the two integers, |
| Example |
result = max(123,67); // function returns 123 |
min
| Prototype |
int min(int a, int b); |
|---|---|
| Description |
Function returns lower of the two integers, |
| Example |
result = min(123,67); // function returns 67 |
rand
| Prototype |
int rand(); |
|---|---|
| Description |
Function returns a sequence of pseudo-random numbers between 0 and 32767. The function will always produce the same sequence of numbers unless srand is called to seed the start point. |
| Example |
while(1) result = rand() ; |
srand
| Prototype |
void srand(unsigned x); |
|---|---|
| Description |
Function uses |
| Example |
srand(9); |
xtoi
| Prototype |
unsigned xtoi(char *s); |
|---|---|
| Description |
Function converts the input string |
| Example |
result = xtoi("1FF"); // result = 511
|
Div Structures
typedef struct divstruct {
int quot;
int rem;
} div_t;
typedef struct ldivstruct {
long quot;
long rem;
} ldiv_t;
typedef struct uldivstruct {
unsigned long quot;
unsigned long rem;
} uldiv_t;
What do you think about this topic ? Send us feedback!




