Namespaces
Variants
Actions

Talk:cpp/language/storage duration

From cppreference.com

Why is register depricated?? 121.242.176.7 07:03, 7 November 2012 (PST)

It is deprecated in the current C++ standard, per paragraphs §7.1.1[dcl.stc]/3 and §D.2[depr.register]. As for why, it's likely because most (all?) existing C++ compilers completely ignore this keyword, and have been for many years. Or, to quote Herb Sutter, It's exactly as meaningful as whitespace. (note that it's not so in the C programming language, where register changes the program semantics) --Cubbi 07:37, 7 November 2012 (PST)

In "external linkage", at the bullet "variables and functions, not listed above (that is, not declared static, and const-qualified but not extern)" the text in the parentheses looks a bit ambiguous. Maybe I'm wrong, but was it meant to be "(that is, not declared static, and non const-qualified)" or something along these lines? --Blastofftek (talk) 02:54, 26 December 2014 (PST)

attempted rewording, better? --Cubbi (talk) 06:18, 26 December 2014 (PST)
Yes, it's perfectly clear now. Thanks --Blastofftek (talk) 06:08, 30 December 2014 (PST)

Contents

[edit] extern declares

Maybe it might also be explicitly stated in Explanation/4) that extern only declares the name, but does not define it (unless an initializer is given). I don't know if this might clutter the explanation, but I think it is important to point out when someone searches for the effects of using the extern keyword. PapaNappa (talk) 07:10, 2 October 2015 (PDT)

it is made more obvious in cpp/language/definition (the first bullet point there), but I agree that someone trying to understand the meaning of a line of code that begins with "extern" would end up here. It's also true that this page is already more cluttered than it needs to be. I added a brief note, but will think about restructuring this.. or at least inserting micro-examples to explain the points. --Cubbi (talk) 07:36, 2 October 2015 (PDT)

[edit] name that denotes a value

In context of the first sentence from the "Linkage" section:

"A name that denotes object, reference, function, type, template, namespace, or value, may have linkage."

...what are the names that denote values? I'm thinking about the enumerators, but I'm not sure. Please help.

[edit] initialization of local variables with thread local storage

"
  • thread storage duration. The storage for the object is allocated when the thread begins and deallocated when the thread ends. Each thread has its own instance of the object. Only objects declared thread_local have this storage duration. thread_local can appear together with static or extern to adjust linkage. See Non-local variables for details on initialization of objects with this storage duration.
(since C++11)
"

This implies that local variables with thread storage are initialized like the non-local ones whereas they actually are initialized at the first time the control passes through them just as it is for static storage duration, as is mentioned in the standard §6.7[stmt.dcl]/4.

So I believe this section needs fixing. --Hgsilverman (talk) 01:54, 6 October 2019 (PDT)

[edit] Does automatic storage not begin at the declaration?

The text says that automatic storage "for the object is allocated at the beginning of the enclosing code block and deallocated at the end". I see the end-point mentioned in the version of the standard that I looked at, but not the begin point. I don't think the difference would be observable in C++, being only relevant for C's VLAs. But still, I'm curious if the begin is defined in terms of the code block. Liamfitz (talk) 12:52, 17 March 2020 (PDT)

I believe this originates from [intro.execution]/1 "An instance of each object with automatic storage duration is associated with each entry into its block.", though it's indeed a curious statement. --Cubbi (talk) 09:56, 18 March 2020 (PDT)
dcl.pre quotes: "An object definition causes storage of appropriate size and alignment to be reserved and any appropriate initialization to be done.". So I think it's only necessary for storage to be allocated at the point of the object's declaration. Of course, implementations are allocating all of the automatic storage at the beginning of functions anyway. --Ybab321 (talk) 07:26, 20 March 2020 (PDT)