Questions tagged [storage-class-specifier]
110 questions
24
votes
4 answers
Confusion about auto keyword in C++
I'm confused by the following piece of code:
#include
using namespace std;
int *foo()
{
//Operation
}
int main ()
{
auto int ret = foo();
}
I compiled the above code under GCC, but I got the following error:
error: two or…

msc
- 33,420
- 29
- 119
- 214
24
votes
4 answers
What is the difference between "File scope" and "program scope"
A variable declared globally is said to having program scope
A variable declared globally with static keyword is said to have file scope.
For example:
int x = 0; // **program scope**
static int y = 0; // **file scope** …

yuvanesh
- 1,093
- 2
- 9
- 19
23
votes
4 answers
Can a variable be declared both static and extern?
Why the following doesn't compile?
...
extern int i;
static int i;
...
but if you reverse the order, it compiles fine.
...
static int i;
extern int i;
...
What is going on here?
user1252446
21
votes
3 answers
Where in a declaration may a storage class specifier be placed?
For example, let's consider the static storage class specifier. Here are a few examples of both valid and ill-formed uses of this storage class specifier:
static int a; // valid
int static b; // valid
static int* c; //…

James McNellis
- 348,265
- 75
- 913
- 977
17
votes
2 answers
Can we place "typedef" specifier anywhere in the declaration?
The syntax of typedef specifier :
typedef
for example:
typedef long unsigned int Int;
It's working fine.
But, If I place typedef anywhere in the declaration, Like this:
long unsigned typedef int Int;
Then, It's also…

msc
- 33,420
- 29
- 119
- 214
15
votes
1 answer
Why is mutable specifier classified to be storage class specifier, but not a qualifier?
When the mutable specifier is used in the declaration of a non-static data member, the data is mutable no matter whether the rest of the object is treated as const. With this fact, we may easily have the impression that mutable specifier is the…
user2486888
11
votes
6 answers
What is the use of Static local variable when we can get a global variable at the same cost?
In C ,what is the use of static storage class when an external variable can serve its purpose at the same cost ie. both occupy storage space in the data segment of the executable.
I have much better scope with external variable.If i want the scope…

Adi
- 729
- 2
- 6
- 13
10
votes
2 answers
Can the 'auto' keyword be used as a storage class specifier in C++11?
Can the auto keyword be used as a storage class specifier in C++11?
Is the following code legal in C++11?
int main() {
auto int x;
}

Sergii
- 255
- 2
- 5
10
votes
4 answers
Extern in multiple files and possible double definition
I was running the following codes compiled together as: gcc A.c B.c -o combined
Program A:
#include
int a=1;
int b;
int main()
{
extern int a,b;
fun();
printf("%d %d\n",a,b);
}
Program B:
int a;
int b=2;
int fun()
{
printf("%d %d\n",a,b);…

tapananand
- 4,392
- 2
- 19
- 35
9
votes
1 answer
What are pure variables?
I was surprised to find that this code compiles:
pure string Foo = SomePureFunction(123);
pure is only mentioned in the context of functions in the online documentation.
What are pure variables, and how are they different from immutable and const…

Maxpm
- 24,113
- 33
- 111
- 170
9
votes
1 answer
Why can't I specify the storage class for formal parameters of a function?
When I do as below the code works fine :
#include
void test( int a)
{
printf("a=%d\n",a);
}
int main()
{
test(10);
return 1;
}
But when I do
#include
void test( auto int a) // Or static int a Or extern int a
{
…

Stubborn
- 780
- 1
- 5
- 20
8
votes
1 answer
constexpr static template function: g++ error is a warning on clang
Consider the following snippet:
#include
template
constexpr int f() { return I * f(); }
template<>
constexpr int f<0>() { return 1; }
int main () {
std::cout << f<5>();
return 0;
}
This code compiles nicely with both…

fedino
- 913
- 1
- 9
- 15
8
votes
1 answer
_Thread_local storage class specifier in C?
I read a note in the book C How to Program 7th about some new standard C storage class named _Thread_local:
The new C standard adds storage class specifier _Thread_local, which
is beyond this book's scope.
I looked for it in Google and here but…
user1129665
5
votes
1 answer
storageclass reclaimPolicy vs pv reclaimPolicy
I wanted to know what's the difference of the reclaimPolicy in StorageClass vs. PersistentVolume.
Currently we created multiple PersistentVolume with a StorageClass that has a reclaimPolicy of Delete, however we changed the PersistentVolume's…

Christian Schmitt
- 837
- 16
- 47
5
votes
3 answers
Does every variable have a storage class in C?
Naively one could think it has, because usually auto is assumed when a storage class keyword is not supplied.
Still, for file-scoped variables putting an auto in front of them gives an error.
#include
auto int x;
int main(void){
x =…

viuser
- 953
- 6
- 19