I wrote a program that uses a const global variable, and I wonder if it is ok to initialize it by calling a Windows API function on the global scope, outside of any other function, and outside of main() or WinMain(). It goes something like this:
#include "stdafx.h"
#include <iostream>
#include "windows.h"
const int i_HRes = GetSystemMetrics(SM_CXSCREEN);
int main()
{ std::cout << "Horizontal screen resolution: " << i_HRes << std::endl;
std::cin.ignore();
return 0;
}
It compiles and runs without errors, but I wonder if calling an API function on the global scope could cause a problem somewhere down the line in consumer software.