Checking stack allocation failure?

Is there a way to fix a failed static allocation, or is the program just failing with segmentation or a bus crash on startup?

Post was inspired by the way the C99 resolves crazy things like char text[n];

EDIT: Thanks. Now I understand that the bold is not a static value. So just check if something like char text[1234];fails, the possible recovery strategies will be the same?

+3
source share
4 answers

char text[n]pushes an array of variable sizes onto the stack. It just includes increasing the stack pointer to n.

, , , , .

+3

, (), , . , n , , , , .

+1

, , .

, ? , (. man 7 signal), printf longjmp (longjmp - , , ) , , , .

, man alloca , "" , SIGSEGV, , , , text [] , , , , [] .

Linux, .

malloc . .

[EDIT]

, ( ) ( , ). , , , . , .

+1
source

This is more a stack distribution than a static one. Failure mode - stack overflow. The most rational policy is to consider it terminal.

Create your code so that it does not overflow the stack, and does not try to make it resistant to stack overflows.

0
source

All Articles