Talk:Automatic variable
From Wikipedia, the free encyclopedia
The code example should be removed. It's unneeded, has undefined behaviour, and, as a matter of fact, does not work as described (on my machine) Dooooomi 14:53, 12 January 2007 (UTC)
- It works for me iff I run gcc with no optimizations. I'll quick-fix the article's statement because I'm not sure what to do with the article overall (I probably agree with you; do whatever you think would improve the overall quality of the article, I guess...) —Isaac Dupree(talk) 21:20, 18 February 2007 (UTC)
- oops again, I was wrong, it prints "1" for me then. Deleting... if it should be restored as a non-working example in a subsection when the article is more developed, that's okay —Isaac Dupree(talk) 21:23, 18 February 2007 (UTC)
[edit] Do automatic variables exist only in C?
This article is very C-specific - do "automatic" variables only exist in C?
129.67.18.164 (talk) 01:45, 31 January 2008 (UTC)
The AUTOMATIC keyword comes, at least, from PL/I before C existed. I believe automatic allocation came from ALGOL before that, but without the keyword. Gah4 (talk) 20:44, 10 June 2008 (UTC)
[edit] Storage class?
The C storage class for automatic variables is auto
What is meant with storage class? --Abdull (talk) 16:51, 6 February 2008 (UTC)
- The storage class is specified using one of the keywords
auto,register,staticorextern. This tells the compiler how to store the variable:auto(automatic - the default). These are allocated by the compiler when they come into scope, and de-allocated when they go out of scope.register. Just likeauto, but also provides a hint to the compiler to store the variable in a processor register (which is faster than main memory). Most modern compilers ignore this hint, since they are quite good at deciding for themselves where to put local variables. You can't take the address of aregistervariable.static. The variable is allocated when it comes into scope, and sticks around until the program exits.extern(external). The variable is defined elsewhere.
- See also: C syntax#Storage duration specifiers.
- 129.67.18.164 (talk) 21:22, 8 February 2008 (UTC)
- PS: ...not forgetting dynamic allocation, of course (but this doesn't have a special keyword):
- Memory can be allocated/de-allocated with the
mallocandfreefunctions.
- Memory can be allocated/de-allocated with the
- 129.67.18.164 (talk) 21:28, 8 February 2008 (UTC)

