|
Do you mean to say that since these are R-values they themselves do not get modified.
Well, yes, my mistake. R-values will not be altered. My statement is incorrect. So now that we are talking at register-level then where and how does C's rules of type conversion come into picture?
|
|
|
|
|
Without talking about registers, types promotion occurs because of (in the original expression) the assignment was done to an integer.
[edit]
actually, running the following code
unsigned int u = 0xFFFFFFFF;
unsigned long long ul = (u << 8);
make me think the above expression cannot be true
[/edit]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, October 22, 2009 4:08 AM
|
|
|
|
|
In the book C-The Complete Reference by Herbert Schildt theree is an example
char ch;
int i;
float f
double d;
result=(ch/i)+(f*d)-(f+i)
Here it does not talk about the data type of the variable "result". In any case, the conversion here is as follows: First ch is converted to int since i is int, then ch/i is performed. The result of ch/i is then converted to double as f*d is double. The final value is a double.
Now if "result" is type float then the final value will be truncated to float and stored in "result", isnt it?
CPallini wrote: types promotion occurs because of (in the original expressio) the assignment was done to an integer.
As we see in the above example the variable to which the final value is assigned, its type matters only when we have solved the expression on the right side.
Please correct me if wrong anywhere.
The mentioned book also says:
"First, all char and short int values are automatically elevated to int"
This seems to be the reason why I don't lose the shifted out bits and also because I store the value back in an unsigned long
modified on Thursday, October 22, 2009 4:51 AM
|
|
|
|
|
Ralph_2 wrote: Now if "result" is type float then the final value will be truncated to float and stored in "result", isnt it?
Yes (and the compiler warns about).
Ralph_2 wrote: As we see in the above example the variable to which the final value is assigned, its type matters only when we have solved the expression on the right side.
Yes. As I added in my previous post, you're right and looks like registers matter...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ralph_2 wrote: "First, all char and short int values are automatically elevated to int"
Yes, and it is also explained here [^].
I didn't know int had such a special role.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your assistance.
So the answer to my question is "Integral promotion"
Now, if only int were 2-bytes then I lose the left-shifted bits and will have a different result for unsigned long = (short<<15) + (char<<9) .....Ahem, i hope this is right now
|
|
|
|
|
This is the assembly output for the statement i = (s << 15) + (c << 9);
movsx eax, WORD PTR _s$[ebp]
shl eax, 15 ; 0000000fH
movsx ecx, BYTE PTR _c$[ebp]
shl ecx, 9
add eax, ecx
mov DWORD PTR _i$[ebp], eax
So as you can see nothing is stored back into any variable.
The two shifts happen in the eax and ecx registers.
It is then added together and the stored into the variable i, which is also 4 bytes in length.
|
|
|
|
|
please have look on the msdn [^]
Величие не Бога может быть недооценена.
|
|
|
|
|
It's little strange for me. I m using CInternetSession, CHttpConnection, CHttpFile classes to make an http request.
It works fine most of time and response comes with status code 200.
But few times response comes with status code -1 (a negative value)
When this happens then it continue to happen for some time so I get -1 for some time.
Can any one tell me when -1 comes, so that I can handle it accordingly.
|
|
|
|
|
Hi,
Negative 1 is not a valid HTTP response code. I would be willing to bet that SendRequest or OpenURL is failing beforehand.
Best Wishes,
-David Delaune
|
|
|
|
|
Thats why I am also surprised. I know, it is not a valid response. I will try to give more info when it will be available. I am currently digging that. This happens occasionally so it is hard to debug and detect.
|
|
|
|
|
Hi,
Did you solve this issue? I would suggest wrapping your CInternetSession code in a try/catch block.
<pre>try
{
}
catch (CInternetException* pEx)
{
switch(pEx->m_dwError)
{
case ERROR_INTERNET_TIMEOUT:
break;
case ERROR_INTERNET_NAME_NOT_RESOLVED:
break;
case ERROR_INTERNET_CANNOT_CONNECT:
break;
default:
break;
}
pEx->Delete();
}</pre><br />
<br />
<br />
Best Wishes,<br />
-David Delaune
|
|
|
|
|
Thanks Randor! I will sure do that. Currently I am not getting that -1.
My new problem is that my program(exe) in not able to connect to internet if it is inside a proxy. How can I deal with proxy?
|
|
|
|
|
Hi,
You can use the InternetCheckConnection Function[^] to check if internet access is available. If you need to connect through a proxy then you can use the INTERNET_OPEN_TYPE_PROXY flag in your CInternetSession constructor. The following documentation may be useful to you:
Enabling Internet Functionality[^]
Best Wishes,
-David Delaune
|
|
|
|
|
 Hi Randor,
I am getting http response code = 407 while using proxy. I know it is for proxy authentication. I wrote the following code. Can you tell me where is my mistake.
std::string responseData("");
DWORD statusCode;
CInternetSession iSession = CInternetSession(L"My Application",1,INTERNET_OPEN_TYPE_PROXY, L"http://proxy.mycompany.com:8080");
CHttpConnection *httpConnection = NULL;
CHttpFile *httpFile = NULL;
char userName[] = "myUsername", password[] = "myPassword";
try
{
iSession.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_CONTROL_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_SEND_TIMEOUT, (int)1000000000);
iSession.SetOption(INTERNET_OPTION_PROXY_USERNAME, userName, strlen(userName) + 1);
iSession.SetOption(INTERNET_OPTION_PROXY_PASSWORD, password, strlen(password) + 1);
httpConnection = iSession.GetHttpConnection(CString("subdomain.maindomain.com"), (INTERNET_PORT) 443);
httpFile = httpConnection->OpenRequest(L"POST", CString("/somepage/"), 0, 1, 0, 0, INTERNET_FLAG_SECURE);
httpConnection->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, (int)1000000000);
CString strHeader;
int contentLength =0;
strHeader = "Content-Type: application/x-amf";
httpFile->AddRequestHeaders(strHeader);
strHeader.Format(L"Content-Length: %d", contentLength);
httpFile->AddRequestHeaders(strHeader);
BOOL x = httpFile->SendRequest(NULL, 0, NULL, contentLength);
httpFile->QueryInfoStatusCode(statusCode);
if(statusCode != 200)
{
responseData = "";
}
char fileData[1024];
int len;
while((len = httpFile->Read(fileData, 1024)) > 0)
responseData.append(fileData, len);
}
catch(CException *ex)
{
WCHAR str[500];
DWORD errorCode = GetLastError();
ex->GetErrorMessage(str, GetLastError());
}
I am using AMF so I specified 443 port while my proxy is using 8080 port.
|
|
|
|
|
I want to log some information before the application crashes. I find the function SetUnhandledExceptionFilter() in MSDN, which enables an application to supersede the top-level exception handler of each thread and process. I'm not sure whether it can catch all exception in a MFC application or not.
I also found some articles about SetUnhandledExceptionFilter in VS2005. It seems that we need to disable the SetUnhandledExceptionFilter function called by CRT. The code is as follows:
void DisableSetUnhandledExceptionFilter()
{
void *addr = (void*)GetProcAddress(LoadLibrary(_T("kernel32.dll")),
"SetUnhandledExceptionFilter");
if (addr)
{
unsigned char code[16];
int size = 0;
code[size++] = 0x33;
code[size++] = 0xC0;
code[size++] = 0xC2;
code[size++] = 0x04;
code[size++] = 0x00;
DWORD dwOldFlag, dwTempFlag;
VirtualProtect(addr, size, PAGE_READWRITE, &dwOldFlag);
WriteProcessMemory(GetCurrentProcess(), addr, code, size, NULL);
VirtualProtect(addr, size, dwOldFlag, &dwTempFlag);
}
}
I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00". Who does understand the code?
In addition, when I debug the code to catch exception, a exception dialog will ask me "Abort, Retry or Ignore". If I select "Abort" or "Ignore', my defined exception funciton will not call. Instead I want it will be called in any case.
So is there some solution for my requirement? Thanks!
|
|
|
|
|
jtasph wrote: I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00". Who does understand the code?
An assembly programmer might recognize those bytes as:
__asm
{
xor eax,eax
ret 0x4
}
But unfortunately its hard to find one these days. They are like the dinosaurs and are nearly extinct.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks Randor for your explanation. Do you know what's the meaning of these assembly codes and how the codes to disable the SetUnhandledExceptionFilter function called by CRT? Do these assembly codes depend on platform? Thanks!
|
|
|
|
|
jtasph wrote: Do you know what's the meaning of these assembly codes and how the codes to disable the SetUnhandledExceptionFilter function called by CRT?
Yes, it overwrites the instructions in memory with new instructions. This causes SetUnhandledExceptionFilter to immediately return.
jtasph wrote: Do these assembly codes depend on platform?
Yes, it is 32 bit assembly instructions.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: They are like the dinosaurs and are nearly extinct.
I thought the dinosaurs *are* extinct.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Some of us dinosaurs have survived. We are like the Coelacanth[^].
Best Wishes,
-David Delaune
|
|
|
|
|
Rajesh R Subramanian wrote: I thought the dinosaurs *are* extinct.
You're actually wrong. There's one of them, for instance, they call Norton-Antivirusex that grabs all the system resources making more damages the viruses could ever do. There is the Eclipsosaurus too, the name comes because it eclipses all your machine power.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Norton
Excuse me? We aren't talking about pigs, are we?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Yes pigs on the wings! Or maybe the great pig in the sky...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
jtasph wrote: I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00".
As David said, it is hex code for "return 0;" . So after you do that WriteProcessMemory (), the SetUnhandledExceptionFilter () will not work any maore it will simply reurn 0. Not only for CRT calls for you also( I am not sure when CRT calls this function. If it has called the SetUnhandledExceptionFilter() before you disable it, the CRT exception handler will work ).
However I suspect the necessity of supressing the CRT exception trough the above method. I guess the you can use the _set_abort_behavior () to control the exception handler of CRT.
More over there is AddVectoredExceptionHandler () function which will be executed before the exception handler specified in SetUnhandledExceptionFilter ().
|
|
|
|
|