If this is a global variable, C requires that it be initialized with something known at compile time; if it requires a call to PQexec()
, this is a runtime thing and not allowed (as your compiler has told you).
If the variable needs to remain global, best is to initialize the re
variable to NULL, and move the actual PQexec()
call/assignment into runtime code just after the database connection has been established.
A non-database example: you cannot initialize any static variable with a runtime call, so:
FILE *infile = fopen("myfile.txt", "r"); // NO
int main()
{
infile = fopen("myfile.txt", "r"); // YES
...
It's ok for the variable to be static; it's only the assignment that must be made at runtime.
Alternatively, if the variable is local, it can be initialized with a runtime call.