Why the use of alloca() is discouraged?
Answers were Sorted based on User's Feedback
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 |
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 |
program to print upper & lower triangle of a matrix
How can I find out how much free space is available on disk?
Is there sort function in c?
What is the difference b/w Structure & Union?
What is p in text message?
Is array a primitive data type in c?
int main() { int days; printf("enter days you are late"); scanf("%d",days); if (days<=5) printf("5o paisa fine"); if (days<=10&&days>=6) printf("1rs fine"); if(days>10) printf("10 rs fine"); if(days=30) printf("membership cancelled"); return 0; } tell me whats wrong in this program? is it right?
Write a program to give following output..... ********* **** **** *** *** ** ** * * ** ** *** *** **** **** *********
How do you determine a file’s attributes?
WHAT IS HIGH LEVEL LANGUAGE?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?