alloca.c

来自「本代码是《C/C++程序员实用大全》的配套代码。网络转载」· C语言 代码 · 共 31 行

C
31
字号
#include <stdio.h>
#include <malloc.h>

void some_function(size_t size)
 {
   int i;
   char *pointer;
   char stack_fix[1];

   stack_fix[0] = NULL;

   if ((pointer = alloca(size)) == NULL)
     printf("Error allocating %u bytes from the stack\n", size);
   else
     {
       for (i = 0; i < size; i++)    
         pointer[i] = i;
       printf("Allocated and used a buffer of %u bytes\n", size);
     }
 }


void main(void)
 {
   some_function(1000);
   some_function(32000);
   some_function(65000);
 }


⌨️ 快捷键说明

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