utility.h

来自「一个很好的粒子滤波算法」· C头文件 代码 · 共 35 行

H
35
字号
#ifndef _UTILITY_H#define _UTILITY_H/* utility.h * coded by Alex Gruenstein for CS107, TA: AndyG * This is the interface to a useful memory allocation * function (GetBlock) and a useful macro (New) *//* macro: New(type) * This is a macro written by Eric Roberts for cs106 that * simplifies memory allocation.  It is used to * allocate memory for a given type (eg a struct). * usage: struct myStruct *m = New(struct myStruct) */#define New(type) ((type) GetBlock(sizeof *((type) NULL)))/* function: GetBlock * this is a modified version of the function developed * by Eric Roberts for cs106.  It is an error checking * wrapper for malloc().  It ensures that the memory * could be allocated, and if not it halts the program * via the assert macro.   * it returns a pointer to free blcok of memory in the heap  * of a given size (in bytes) */void *GetBlock(unsigned int size);/* function: CopyString * this is a utility function supplied by cs107 that I have * modified slightly. * it places a copy of a string in memory that it allocates * on the heap * returns: a pointer to the new string */char *CopyString(const char *s);#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?