Is the following code legal?
int add(int a, int b) { return a + b; }
int some_global_variable = add(1, 2);
int main() { /* ... */ }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. Yes, it is.
Static initializers may call functions, as long as they’re in scope.
[dcl.decl](2003 wording, 8/2):[dcl.init](2003 wording, 8.5/2):(Don’t be misled by the lack of the
statickeyword, which has all sorts of meanings. Your variablemyvaris declared at namespace scope, and thus has static storage duration.)