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

write a c program to calculate the income tax of the employees in an organization where the conditions are given as. (I.T. = 0 if income <100000 I.T = 10% if income _< 200000 it = 20% if income >_ 200000)

7 Answers   Consultancy, DBU, FD, JK Associates, Kobe, Satyam,


what is the difference b/w compiler and debugger?

2 Answers   Assurgent,


Why main is used in c?

0 Answers  


can we change the default calling convention in c if yes than how.........?

0 Answers   Aptech,


what will be the output for the following program? main() { char ch = 'k'; char c; printf("%c",c); }

3 Answers  






Explain how can you check to see whether a symbol is defined?

0 Answers  


inline function is there in c language?

4 Answers  


If we give two names then this displays the connection between the two people. It is nothing but flames game

1 Answers  


Write a program to generate prime factors of a given integer?

2 Answers  


what is a void pointer?

2 Answers  


how to find anagram without using string functions using only loops in c programming

1 Answers   Mind Tree, TCS,


how c source file in converted to exe file

5 Answers   KPIT,


Categories