Can I declare an extern variable static?

What the title says.

 
extern static int x(void);
The example you gave is not a variable. It declares a nullary function that returns an int.

In any case, no, you cannot. This will not compile. Although you could do something like this:
1
2
3
4
namespace
{
    extern int x(void);
}


This basically declares an int-returning function that takes no parameters as having external linkage, but wrapping it in an anonymous namespace makes that linkage static, so it becomes completely useless. It makes no sense to do this, of course.
Ok. Ty 👌
Hm.. could I scope an extern variable?

1
2
3
4
void func() {
  extern int x(void);
  x();
}
Once again, it is an extern function, not a variable.
But yes, you could do that.
Sorry, I keeps saying that. I’m just using a function because why not. It could be anything, function’s just most convenient I guess.

1
2
3
4
5
extern class X;

extern int x(void);

extern std::vector xx;


Thanks.
Topic archived. No new replies allowed.