Go Back   The UNIX and Linux Forums > Top Forums > Programming
.
google site




Thread: Heap and stack
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 04-28-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,172

Code:
main()
{
int *a;
.
.
}

a, itself, is on the stack. What part of memory a "is aimed at" is indeterminate in your code. It could be anywhere. Show us something like a=&some_int and then we can tell you. As it is there is no way to answer.

Next problem - gets works on string pointers, not int *
So I have no idea where gets would be working.

If you are worried about heap being "slower" than stack, don't. Unless you can definitely show that a gets call is a bottleneck - by using a profiler - it is a waste of programmer time to fuss over stuff like that.

gets works against the actual memory referenced by the pointer, it has nothing to do with where the pointer itself lives.

Andryk - void main () is a BAD idea, especially in a UNIX forum.