I know I'm stubborn, please don't take it seriously :)
but I still don't think a compiler should change anything that is shared with user(the main() function). no matter what and how you do with your initialization, the user's environment should be left clean.
now the user says: "hey, I've done anything yet, and I'm wrong, with error code 1113."
MinGW say: "you're not wrong, you should check yourself in a better way, check the return value first, then the error code"
user say: "That's my habbit, it always work with VC"
it's not right to kill a program if it's written with bad habit, sounds like kill a man if he has a bad habit. it's not the compiler's business, IMO, if it changes something, it should restore it back.
this's my another piece of code, a program to very the result of tls initialization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// tls_check.cpp
#define _WIN32_WINNT 0x600
#include <windows.h>
#include <iostream>
using namespace std;
#include "tls.h"
int main() {
int err = GetLastError(); // verify the tls result, it should be 999, but it's 1113
if(err != 0) {
//call_some_api_that_not_available_in_tls();
cout << "failed on initializing" << endl;
}
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// tls.h
void NTAPI tls_initialize(void* h, DWORD dwReason, PVOID pv) {
//if(err_occur_when_initlizing()) {
::SetLastError(999);
// }
}
extern "C" {
const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".CRT$XLB"))) = {
(DWORD)&tls_initialize,
(DWORD)NULL
};
}
|
since the tls callback is limited, lots of api are not available, so I put the error handling in main() function, and it got the error 1113.
I'm not waiting to get a workaround for this code, there always be a workaround, I'm just trying to say, a lot of programs may have this 1113 problem, what's strange to me is I didn't found anything about this from google, there isn't any documentation, no one had even talked about this.