Page 1 of 1

Stack idea

Posted: Fri Jan 28, 2011 3:50 pm
by bergen110
Hello,

I have the idea to make a sort of stack in C that writes to a memory location.
But is this idea efficient? or are there better ways to store fast a variable, if you need to use it short after you store it?

Re: Stack idea

Posted: Fri Jan 28, 2011 3:52 pm
by gravaera
Yo,

Code: Select all

int myFunction(void)
{
   int myLocalArg;

   // Do something;
};
The answer to your question is on line 3.

--Peace out,
gravaera

Re: Stack idea

Posted: Fri Jan 28, 2011 3:58 pm
by bergen110
I've made a fault in my starting post. i want to use it in another function.
I know that i can use global vars, but a simple call to a function that writes it to a memory location i simpler?

Re: Stack idea

Posted: Fri Jan 28, 2011 4:12 pm
by gerryg400
Like alloca() ?

Re: Stack idea

Posted: Fri Jan 28, 2011 4:16 pm
by bergen110
Yes, thats the solution, thanks!
i am going to implement that function

Re: Stack idea

Posted: Fri Jan 28, 2011 4:38 pm
by JamesM
bergen110 wrote:Yes, thats the solution, thanks!
i am going to implement that function
It's a compiler intrinsic. It comes with GCC.

Re: Stack idea

Posted: Fri Jan 28, 2011 4:42 pm
by bergen110
So i can use it without writing it?
Pretty cool!