Function parameters must be a valid type. The value returned is the last statement in the function body.
Example:
(func (strlen (char * str))
{
(int i = 0);
(while ((!= (str[i]) '\0')) {
(i = (+ i 1))
})
(i)
})
In this example, the function name is strlen. This function takes a string as parameter and return the length of it.
Recursive calls
Here an example of the Fibonacci function with the function fib-it that is called recursively.
Builtins
The C-- language provide some builtin functions:
Function Name
Description
Prototype
malloc
The malloc function allocates size bytes and returns a pointer to the allocated memory.
char * malloc(int size)
write
write writes up to size bytes from the buffer starting at buffer to the file referred to by the file descriptor fd.
int write(int fd, char *buffer,int size)
puts
puts writes the string str and a trailing newline to stdout
int puts(string str)
Examples
Malloc
In this case, we are manipulating pointers after using the malloc function to create a char * with the characters "J" "B" and "D" in it. The size of str is 4 because of the malloc.
Write
We define an integer i with the value 48 and cast it in the char type. After that, we use the write function to display the character in the standard output by sending the address of it since the function takes a pointer.
Puts
We define a stringstr and we use the function puts to display it in the standard output.
Rewriting C builtins
Here are some example of implementations of function made during the Epitech C pool with the C-- :