This topic has been archived. It cannot be replied.
-
工作学习 / IT杂谈 / C programers, please come invoid functionA()
{ char a[50];
functionB(&a[0]); }
Is this a bug? the address &a[0] in heap, can I use it outside functionA? does it cause wrong memory access? Thanks!!
-arual(游子-闲溜达);
2005-3-24
{173}
(#2200444@0)
-
Is the C local variable in Heap other than in the Stack?I think it should in the stack. If you u using malloc it will using heap.
-nealzhao(neal);
2005-3-24
(#2200491@0)
-
sorry, my fault. local is in stack, is it safe to use it outside function? even it will come back, but any possiblity cause crash?
-arual(游子-闲溜达);
2005-3-24
(#2200528@0)
-
especially in mult-thread environment?
-arual(游子-闲溜达);
2005-3-24
(#2200529@0)
-
It will be thread safe if it is a local variable in stack.
-nealzhao(neal);
2005-3-24
(#2200559@0)
-
array a is local to functionA. It is in stack. when A exit, array a doesn't exist any more. but if you somehow record the address of a, you can still access it by address, the content in it may be overwritten.
-deepthought(deepthought);
2005-3-24
(#2200536@0)
-
Thanks.So before A exit, I can use local value's address saftly outside function.right?
-arual(游子-闲溜达);
2005-3-24
(#2200591@0)
-
I don't see any problem from this code.
-benbenli(笨笨);
2005-3-24
(#2200882@0)