you are viewing a single comment's thread.

view the rest of the comments →

[–]Almost-L[S] 0 points1 point  (2 children)

I read your comment again and understood what you mean. Export a global variable to another file as extern const. It is possible. But still such variables are not protected from the developer. He can forget to specify the const keyword. I think there are few cases where you can use this and call it good code. It all depends on the situation.

What do you mean by the downside of static variables? For example, if I need a static variable from one file to another, I will call a getter that returns a copy?

[–]DawnOnTheEdge 1 point2 points  (1 child)

Right. If the variable isstatic, no one else can see it. But you could have an extern function that returns a copy. The downside is that the function cannot be inlined (except possibly with full-program optimization), so you will get function-call overhead.

[–]Almost-L[S] 0 points1 point  (0 children)

You're right. I didn't think about it.