Skip to main content

Timeline for Global variable - memory allocation

Current License: CC BY-SA 4.0

29 events
when toggle format what by license comment
Mar 17, 2021 at 21:48 vote accept Aljaz Jelen
Feb 3, 2021 at 20:54 comment added Aljaz Jelen I have no technical input here. Just wanted to thank everyone for comments and answers. I will review @jonk answer as well and then decide which one gives me most valueable information. But definitely thanks everyon! :)
Feb 3, 2021 at 19:15 comment added jonk @le_top All of the text above is my own. I do refer to other sites if I draw any information from them or wish to refer to them to help clarify a phrase or word I'm using. But to the best of my knowledge, the words are mine. I use the quoting facility here as interludes, but using my own words. If you have very specific changes and you succeed in making a good case, I'll be more than glad to improve the answer. Beyond that, I feel we've flogged this horse sufficiently. (Your confusion or your suggesting it for others, should there be any, is not necessarily mine or actually that of others.)
Feb 3, 2021 at 19:08 comment added le_top Further it is not clear if the quote is your own or someone else's (because it is a quote). I am not doing a detailed review of your post that has been time consuming to write. I can glance that you also talk about optimisation - I put this differently in a question I ask candidates sometimes : where can a variable be located in a program? One of the answers is nowhere (optimised out), others are RAM, ROM, stack, instruction, etc.
Feb 3, 2021 at 19:04 comment added le_top We can say that my comment interpreted that the "volatile" keyword led to designating "volatile variables" as "volatile memory", reinforce by the phrase that I mentioned above. Therefore I suggested to revisit this explication. I stopped reading there. On your profile you explain that complete answers may harm a questionner, but I think that what is "harmfull" here is that there is no introduction to how the long answer relates to the question. I suggest that you summarize the answer and then provide details - vimeo.com/16383361 .
Feb 3, 2021 at 17:36 comment added jonk @le_top If you carefully identify everywhere I may have misled you in my writing, I'll go back and try to use what you offer and be pedantic about adding the necessary verbage for you. But it did appear not just to me but to at least one other that you misunderstood me, earlier.
Feb 3, 2021 at 16:48 comment added le_top @jonk Your phrase "volatile" [means] at least [...] uninitialized values at power-on and writable, does not apply to the volatile keyword but seems to refer to the keyword because of the quotes. You can improve this by writing "volatile memory". I am not trapped by a narrow perspective, I am perfectly at ease with electronics and with software. Non-volatile memory is not necessarily "ROM" or non-modifiable - "RAM" can be perfectly non-volatile when it is battery powered.
Feb 3, 2021 at 15:55 comment added jonk @PeterSmith Yes. I worked with the R2000 (and spent time at MIPS with Hennessey) and they used a fixed register (I think $31?). But this was by no means the first such instance. The PDP-11 JSR instruction allows you to specify any of the registers. This allowed for very, very convenient co-routines that could JSR back and forth between each other without any need for stack access.
Feb 3, 2021 at 15:52 comment added Peter Smith I recall that MIPS devices from not so very long ago (still?) used the R registers for the return address from a subroutine call.
Feb 3, 2021 at 15:44 history edited jonk CC BY-SA 4.0
deleted 429 characters in body
Feb 3, 2021 at 15:38 history edited jonk CC BY-SA 4.0
deleted 429 characters in body
Feb 3, 2021 at 14:31 history edited jonk CC BY-SA 4.0
added 1440 characters in body
Feb 3, 2021 at 14:15 history edited jonk CC BY-SA 4.0
added 255 characters in body
Feb 3, 2021 at 14:13 comment added jonk @PeterSmith I know it's very similar. I was reading the committee debates at the time and hoping very much that they would include the qualifier. They did. And I was quite happy. However, the meaning within the language has taken on its own life. It's tethered to its roots, but has its own future, as well. Perhaps an analog might be that c++ isn't c, but is tethered to it. Maybe that's not so good. But it came to mind. And thanks for the kind comment about the discussion!
Feb 3, 2021 at 14:10 history edited jonk CC BY-SA 4.0
added 255 characters in body
Feb 3, 2021 at 14:09 comment added Peter Smith The semantics of volatile (in the language sense) is actually not so very far from the hardware meaning in a way. Volatile for hardware means you have no idea of the state of the internals at powerup; for the language semantics it means that the compiler will have no idea the variable might even be touched and that the state of the variable must be treated as unknown and not optimised out. Excellent discussion.
Feb 3, 2021 at 13:59 history edited jonk CC BY-SA 4.0
added 826 characters in body
Feb 3, 2021 at 13:36 history edited jonk CC BY-SA 4.0
added 706 characters in body
Feb 3, 2021 at 13:25 comment added jonk @Lundin Yes, it appeared in the latter part of the 1980s. C wasn't even standardized until 1989, more than a decade after I was already using it with in writing Unix v6 kernel code. And by that time, those working with me had been using it for at least three years prior to that. The Unix C compiler, itself, was the only standard beforehand. 'Volatile' appeared in 1989 as part of the standard primarily to the semantics needed for memory mapped hardware devices.
Feb 3, 2021 at 13:18 history edited jonk CC BY-SA 4.0
added 471 characters in body
Feb 3, 2021 at 13:16 comment added Lundin I think @jonk is correct in that the term volatile memory pre-dates C volatile keyword. It doesn't seem to be present in the K&R 1st edition book from 1978, so most likely this keyword was formalized in the 1980s and not standardized until 1989 with "ANSI-C". Regardless, embedded system C programmers are expected to know about the terms volatile memory and non-volatile memory, since those are industry de facto standard terms since forever.
Feb 3, 2021 at 13:03 history edited jonk CC BY-SA 4.0
added 1389 characters in body
Feb 3, 2021 at 12:43 comment added jonk @awjlogan Yup. That's what I meant. I gather le_top is trapped within a narrow perspective. But the fact or it means that I can add something to clarify for those who are so limited in viewpoint. So I will. Thanks for helping clarify, though. Appreciated.
Feb 3, 2021 at 12:41 comment added jonk @le_top I carefully discussed my terms (I should not have needed to, but I did just the same) at the very top of my answer. It has nothing to do with compiler languages and everything to do with hardware. This is an electronics site, not a C language site. I take it you are completely unfamiliar with the use of the term 'volatile' in electronics?
Feb 3, 2021 at 8:44 comment added awjlogan @le_top I think jonk means volatile in the sense of not retained through power down, whereas you are referring to a variable declared as volatile.
Feb 3, 2021 at 7:58 comment added le_top I suggest that you revisit your explications with regards to "volatile". Volatile memory is not considered random, but it requires that the compiler ensure that all operations are performed. For instance the compiler can not skip a read because it made a read in the previous statement. You can have a volatile memory in ROM if you map it there - it does not have to be writable.
Feb 3, 2021 at 7:00 history edited jonk CC BY-SA 4.0
added 1 character in body
Feb 3, 2021 at 2:21 history edited jonk CC BY-SA 4.0
edited body
Feb 3, 2021 at 0:17 history answered jonk CC BY-SA 4.0