mb_cmalloc |
void* mb_calloc( size_t size )
Allocates a memory block with all elements initialized to 0 that can be used for variables and strings and arrays in MyBASIC2. An allocated memory block must be deallocated using the mb_free function.
Example
// Simple function that returns the string "This is My String!"
int _my_func( mb_interpreter_t* s, void** l ) { mb_assert( s && l );
mb_check( mb_attempt_open_bracket( s, l ) ); mb_check( mb_attempt_close_bracket( s, l ) );
const char* pMyString = "This is My String!";
char* pString = (char*)mb_calloc( strlen( pMyString ) + 1 );
if ( pString ) { strcpy( pString, pMyString ); }
mb_check( mb_push_string( s, l, pString ) );
return MB_FUNC_OK; } |