Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it guaranteed that the array specified always get enough space?

Tags:

arrays

c

Unlike the malloc , I have never seen a if statement for checking whether the array has got enough space. So is it guranteed that the arrays always get enough space even though they are allocated in the stack? And what to do in case otherwise?

like image 420
Shash Avatar asked Dec 28 '25 21:12

Shash


1 Answers

No guarantee at all.

There's no way to verify whether the stack allocation was successful or not. The C standard doesn't mandate any limits (min or max).

So you should check with your operating system which typically allocates a fixed size stack. For example, on my Ubuntu system, the stack size is 1MB. So it depends on your operating system.

In fact, if you start to have doubts whether stack size is enough, you should go for dynamic allocation (malloc).

like image 185
P.P Avatar answered Dec 31 '25 12:12

P.P