Why the use of alloca() is discouraged?

Answers were Sorted based on User's Feedback



Why the use of alloca() is discouraged? ..

Answer / johnson

Sorry, that is not strictly correct. According to the man page:

"The alloca() function allocates size bytes of space in the
stack frame of the caller, and returns a pointer to the
allocated block. This temporary space is automatically freed
when the caller returns."

Now this is the real reason:
" If the allocated block is beyond the current stack limit,
the resulting behavior is undefined."

Is This Answer Correct ?    12 Yes 0 No

Why the use of alloca() is discouraged? ..

Answer / sathish kumar

Hi All,

If you use alloca inside a function when it retuns from
function it will be resulting in memory leak. Thats why
its discouraged to use.

Thanks & Regards
Sathish Kumar

Is This Answer Correct ?    2 Yes 5 No

Post New Answer

More C Interview Questions

What is a static variable in c?

0 Answers  


What is the difference between exit() and _exit() function?

0 Answers  


how can be easily placed in TCS.

0 Answers   TCS,


difference between ordinary variable and pointer in C?

2 Answers  


Differentiate between declaring a variable and defining a variable?

0 Answers  






why return type of main is not necessary in linux

0 Answers   TCS,


Explain the differences between public, protected, private and internal.

2 Answers  


Is array a primitive data type in c?

0 Answers  


write a program to sum of its digit with using control structure or with out using loop. for ex: let the number is 25634 then answer will be=2+5+6+3+4=20

4 Answers  


identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

8 Answers   TCS,


what is data structure

5 Answers   Maveric, TCS,


how to introdu5ce my self in serco

0 Answers  


Categories