static variable declaration

Hi all. Just a simple question. If i declare 2 variables like this
 
static int first, second;


will both of them be declared static or will only first be declared static and second a regular variable?
If you have to ask... that means it is unclear and you probably shouldn't do that in your code. If it's confusing to you now, then it might be confusing to you later (and possibly confusing to anyone else who reads your code).

I say declare then on separate lines.




Though to answer your question, they will both be static.
A simple answer for a simple question:
Both of them will be static.

Commas work like a list. Think of it this way:
In the sentence "I bought ice cream, candy, and apples", not only did you buy ice cream, but you also bought candy and apples. So, when you put
static int ice_cream, candy, apples;
Not only is ice_cream a static integer, but so are candy and apples.


Last edited on
Thank you both. I kind of knew they would be both static too but I just needed some confirmation
A simple answer for a simple question:
It is not that simple. There is several confusing rules (leftover from C, though there is no reason to have them there too).

int* x, y, z(int);
Here x is a pointer to int, y is a plain int and z is a forward-declared function taking int and returning an int.
However if we do that:
1
2
typedef int* intp;
intp x, y;
both x and y are pointers to int

And finally:
1
2
3
4
5
using intp = int*;
intp x, y;
int* a, b;
static_assert(typeid(x) == typeid(a), "Not Error");
static_assert(typeid(y) == typeid(b), "Error");
Thanks for the correction, but to be clear, I said that to enthusiastically answer his question. He said "simple question" so I typed it in a joyous way.
Topic archived. No new replies allowed.