calloc.c
来自「一组基础的C库的实现」· C语言 代码 · 共 53 行
C
53 行
/* $Id: calloc.c 262 2006-11-16 07:34:57Z solar $ *//* Release $Name$ *//* void * calloc( size_t, size_t ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will.*/#include <stdlib.h>#include <string.h>#ifndef REGTESTvoid * calloc( size_t nmemb, size_t size ){ /* assign memory for nmemb elements of given size */ void * rc = malloc( nmemb * size ); if ( rc != NULL ) { /* zero-initialize the memory */ memset( rc, 0, nmemb * size ); } return rc;}#endif#ifdef TEST#include <_PDCLIB_test.h>int main(){ char * s; BEGIN_TESTS; TESTCASE( ( s = calloc( 3, 2 ) ) != NULL ); TESTCASE( s[0] == '\0' ); TESTCASE( s[5] == '\0' ); free( s ); TESTCASE( ( s = calloc( 6, 1 ) ) != NULL ); TESTCASE( s[0] == '\0' ); TESTCASE( s[5] == '\0' ); free( s ); TESTCASE( ( s = calloc( 1, 6 ) ) != NULL ); TESTCASE( s[0] == '\0' ); TESTCASE( s[5] == '\0' ); free( s ); return TEST_RESULTS;}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?