1.c

来自「分析C程序中的词法,如是否为关键字或变量等.」· C语言 代码 · 共 49 行

C
49 行
字号
#include "hprof.h"
auto,main,break,case,char,const,struct,continue,do,define,default,
double,else,enum,extern,for,goto,int,if,include,long,register,
return,scanf,struct,short,static,sizeof,switch,printf,void,while
static int 
real_size(int alignment, int nbytes)
{
    if ( alignment > 1 ) 
    {
	int wasted;
	wasted = alignment - ( nbytes % alignment );
	if ( wasted != alignment ) 
	{
	    nbytes += wasted;
	}
    }
    return nbytes;
}

static void
add_block(Blocks *blocks, int nbytes)
{
    int header_size;
    int block_size;
    BlockHeader *block_header;
    HPROF_ASSERT(blocks!=NULL);
    HPROF_ASSERT(nbytes>0);
    header_size= real_size(blocks->alignment, sizeof(BlockHeader));
    block_size= blocks->elem_size*blocks->population;
    if ( nbytes > block_size ) {
	block_size = real_size(blocks->alignment, nbytes);
    }
    block_header= (BlockHeader*)HPROF_MALLOC(block_size+header_size);
    block_header->next   = NULL;
    block_header->bytes_left = block_size;
    block_header->next_pos   = header_size;
   
    /* Link in new block */
    if ( blocks->current_block != NULL ) {
        blocks->current_block->next = block_header;
    }
    blocks->current_block = block_header;
    if ( blocks->first_block == NULL ) {
        blocks->first_block = block_header;
   }
}


⌨️ 快捷键说明

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