Talk:Static variable

message: There are a variety of variables, I don't know if it would be adequate to fit all of them on the one variable page. I feel that we would need stubs for each type of variable on the main page. While variable types should have their own pages elaborated with examples in a variety of languages. Below is some info on what should be covered.
mkhjk
Static Variables
      -exist from the time of creation until the termination of the program.
      -this can be used to implement history sensitive subprograms
      -because these variable are directly addressed they are more efficient
      -although with the static binding you loose the ability to call subprograms recursively
      -languages such as C and C++ allow you to specify a variable to be static with the static keyword
Stack-Dynamic Variables
      -storage bindings are created during runtime
      -typing is bound at compile time
      -variable is allocated memory on the runtime stack
      -can be used to implement recursive subprograms
Explicit Heap-Dynamic Variables
      -"nameless (abstract) memory cells that are allocated and deallocated by explicit run-time instuctions"
      -"these variables are allocated and deallocated to the heap"
      -"can only be referenced through pointers"
Implicit Heap-Dynamic Variables
      -"have the highest degree of flexibility"
      -"bound to heap storage only when they are assigned values."
      
Concepts of Programming Languages by Robert W. Sebesta
Serialloop (talk) 21:38, 1 May 2009 (UTC)
thread_title: Untitled

message: Static variable is just a type of variable, there isn't that much to say about it - should be a section in Variable. Ripper234 17:29, 4 April 2006 (UTC)
replies: text: Agreed. I removed the untrue claims and cleaned up the rest. There's not much left, so it should definitely merge. The Rod (☎ Smith) 19:54, 4 April 2006 (UTC)
thread_title:  Merge proposed 

message: What to do about the fact that a static variable in Visual Basic and a local static variable in C are something else? Rp (talk) 20:12, 8 January 2009 (UTC)
thread_title:  Static variables in Visual Basic 

message: do you get a faster function call with globale variables instead of static ones?
are global ones faster? - maybe because static variables have to be pushed to stack and next time popped.  —Preceding unsigned comment added by 62.202.30.116 (talk) 07:39, 11 March 2009 (UTC)
thread_title:  what about performance? 

message: I've just revised the article. Please check my work.
I carefully avoided mentioning C's default scope/extent rules, and removed a mention of the "auto" keyword. ISTM that this topic should be left to articles about C, keeping this article simpler and more generic.
Static local variables were available in ALGOL 60, where they were called "own variables". Neither ALGOL W nor ALGOL 68 had own variables. (The problem was that all three languages allowed arrays whose bounds were specified at run time, so you could declare an own array of n elements where n had a different value every time the function was called.) Does anyone think we should mention own variables?
Cheers, CWC 15:01, 17 October 2009 (UTC)
thread_title:  October 2009 

message: I've just done a substantial rewrite/reorganization of this section, adding a little detail. I don't want to add too much detail, lest the C/C++/ObjC content overwhelm the general content about static variables. So I decided not to mention:
*that C has special rules about initial values for static variables
*that the first call to a function with static local variables will see whatever values said variables were initialized with
*that local static variables can be defined in, and so visible in, a nested scope rather than the whole function
*the difference between declarations and definitions (which is immensely important with extern variables)
*that static global variables are not visible in inner scopes if hidden by variables with the same name
I want this article to be about the language-independent concept, not the C storage class, so I would rather not see the section grow much further.
Aside. I'm surprised to see that the C (programming language) article does not mention storage classes. If someone wants Wikipedia to cover C storage classes in more detail, it would be best to do so in that article or a spinoff article.
Cheers, CWC 15:26, 14 July 2010 (UTC)
thread_title:  Section about C, C++, Objective-C 

message: Following edits adding more details to the section about C family languages, I've revised that section. I've used a simple table to summarize the effects of static, extern and auto/register on lifetime and linkage, and added something about the two meanings of the term "static variable" in these languages. (I even said those two meanings are "easy to confuse".)
As I said above, I don't want this article to cover C's storage classes in detail (let alone C++'s), but it seems useful to provide more detail than my earlier edits did. What do other editors think? Corrections welcome. Cheers, CWC 07:53, 29 May 2011 (UTC)
thread_title:  May 2011 

message: Any objections that we write  x++  instead?  x = x + 1  sounds so BASIC to me. ;) -andy 77.13.74.98 (talk) 06:51, 30 September 2012 (UTC)
thread_title:  x = x + 1 

message: User  has suggested merging our article on Static memory allocation into this one. Here's a place for other editors to comment.
* Support. We should not have two articles for essentially the same topic. CWC 06:48, 14 January 2013 (UTC)
replies: text: . No one mentioned any reasons not to merge. So I merged the entire static memory allocation article into this static variable article. --DavidCary (talk) 21:39, 9 July 2016 (UTC)
thread_title:  Merge [[Static memory allocation]] here? 

message: ie.
void func() {
	static int x; // is x here initialized always with zero? I was testing with gcc, and there is it in my tests always zero
        // but in assembler code is not zero assignment!
        // in linux kernel is this also used!
        // gcc doesnt generate any warnings
        // talk about this should be in articel
}
i.e. from linux kernel
static int azx_probe(struct pci_dev *pci,
		     const struct pci_device_id *pci_id)
{
	static int dev; // is not assigned
	struct snd_card *card;
	struct azx *chip;
	bool schedule_probe;
	int err;
	if (dev >= SNDRV_CARDS) // is used without assignment
		return -ENODEV;
...
— Preceding unsigned comment added by 79.215.101.154 (talk) 11:56, 31 May 2014
:C compilers are required to (arrange that) all static variables with no explicit initialization contain zeroes at the start of execution. (The C standards leave a little wiggle room about the meaning of "zeroes" here, but on modern systems statics default to all zero bits, meaning integer 0, float 0.0, pointer NULL etc.) Languages derived from C generally have the same rule; assembler does not. Hope this helps -- CWC 04:11, 1 June 2014 (UTC)
thread_title:  is static variable assignment needed? 

message: Static variables date from at least FORTRAN II (1958) where they were known as 'COMMON' variables. 121.200.27.15 (talk) 06:45, 22 April 2023 (UTC)
thread_title:  Date from at least ... 1958