|
The compiler is probably optimizing because ca is declared const. The compiler can replace any references to ca and directly insert 200.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Your reply sounds reasonable, but both the varibale of 'ca' and 'cb' have same address in memory, but their value is different, I just can't unstand it, it must be somewhere else for 'ca' or 'cb', is that correct!
|
|
|
|
|
cadinfo wrote:
, but both the varibale of 'ca' and 'cb' have same address in memory
After the compiler optimization, 'ca' has NO address in memory any more. It simply is the value '200' known at compile time.
You promised not to change this value by declaring it const, remember?
So the compiler can replace every access to 'ca' by the value '200' at compile time.
In effect, this is a little like a precompiler #define, in that both methods don't make a variable.
|
|
|
|
|
jhwurmbach wrote:
,After the compiler optimization, 'ca' has NO address in memory any more.
but in debug mode or use
cout<<"&ca="<<&ca<<"\t&cb="<<cb<<endl;
you will find address of ca is same to cb, and in debug time the value of ca will change to new value, but when output it return to '200'
|
|
|
|
|
Well, I did look at the assembly-code, after tracing did not reveal why '2400' is changed to '200' in output:
16: cout<<"ca="<<ca<<"\tcb="<<cb<<endl;
004017BE push offset @ILT+195(std::endl) (004010c8)
004017C3 mov edx,dword ptr [ebp-8]
004017C6 mov eax,dword ptr [edx]
004017C8 push eax
004017C9 push offset string "\tcb=" (0046e020)
004017CE push 0C8h
004017D3 push offset string "ca=" (0046e01c)
004017D8 push offset std::cout (0047c0c0)
004017DD call @ILT+640(std::operator<<) (00401285)
004017E2 add esp,8
004017E5 mov ecx,eax
004017E7 call @ILT+250(std::basic_ostream<char,std::char_traits<char> >::operator<< ) (004010ff)
At address 004017CE you see how the code inserts the '200' (0C8h) into the output stream and does not access the variable at [ebp-4].
Some sort of optimisation, even in debug mode.
But you can't blame the compiler, after all you *promised* that 'ca' would not change!
|
|
|
|
|
I have an MFC MDI App. In this I want to copy a bmp from Folder1 into folder2 .How does one do this?
Thanks,
ns
|
|
|
|
|
You could use CopyFile(), look it up in MSDN...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
SHFileOperation could find some use as well
|
|
|
|
|
I created a new database using ADOX. When I go to add ecords to it, they are added haphazardly, not in order. THe latest one might be in the middle somewhere...
How do I ensure that they get added in order?
Heres my code:
try
{
ADO::_RecordsetPtr rsBlob (__uuidof(ADO::Recordset) );
m_pCommand->CommandText="SELECT * FROM tblTest" ;
rsBlob->CursorLocation = ADO::adUseClient;
rsBlob->Open ((IDispatch *) m_pCommand, vtMissing, ADO::adOpenKeyset,
ADO::adLockOptimistic, -1);
rsBlob->AddNew();
rsBlob->Fields->Item["A_Image"]->Value = bstrFile;
char* charID = new char[strID.GetLength()+1];
strcpy(charID, strID);
rsBlob->Fields->Item["MINE_TYPE"]->Value = charID;
delete[] charID;
}
Thanks for helping,
ns
|
|
|
|
|
The SQL database does not guarantees, that it stores records in particular order (even if it often does). It's by design. The order of returned records is defined by the ORDER BY clause of SELECT query.
Pavel
Sonork 100.15206
|
|
|
|
|
Can someone give me a practical example/reason of why classes can contain static member functions, aside from data encapsulation I'm not sure I see their purpose. We were talking about them today in a class that I have and my professor couldn't give me any specific reason as to why we have this. Any ideas would be great as I am just a little curious (aside from those that say "So you can call method X without object instantiation" ). Thanks.
Nick Parker
|
|
|
|
|
I am writing a wrapper for XML in C# at the moment, and one thing that takes a few lines of code normally is to take a node and return the text value, if any, associated with it. node.text simply won't do the job well. By making the function GetNodeValue static, I am able to call it if I have a node kicking around but I don't have an instance of my class. The class essentially becomes a namespace that contains functions which I may have a use for even if I don't have an instance of the class at that point in time, so it saves me building the object needlessly.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Gotcha, I think that pretty much explains it.
Nick Parker
|
|
|
|
|
One of the good uses I've found for static members is factory like functions. If I have a class that I dont' want anybody but me to be able to instanciate I make all of hte constructors private. Then I allow creation through static member functions. This comes in handy sometimes especially in other languages such as C# and Java
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Sometimes you need a class attribute, which is shared between all instances of the class.
Pavel
Sonork 100.15206
|
|
|
|
|
Pavel Klocek wrote:
Sometimes you need a class attribute, which is shared between all instances of the class.
Could you elaborate?
Nick Parker
|
|
|
|
|
If I have the data in 1.prv and I want embed that data in program while compile.
Can I include like this #include "C:/1.prv"?
Thank you.
|
|
|
|
|
Dunno - have you tried ?
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
hey all. I am working on a single document MFC program and currently have a problem. Under a CFormView document, there is the GetDocument function. Is there any way to use this function or get the same effect in a CDialog document? Any help is appreciated. Thanks.
Brad Jennings
|
|
|
|
|
CYourDoc *pDoc = (CYourDoc *)(((CFrameWnd *)AfxGetMainWnd())->GetActiveView()->GetDocument()); I guess this is what you're after.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I have a vector with pointers to an object. Now for each object I need to call a function Update(float fTime). Now when I write something like this:
for_each(...begin(), ...end(), mem_fun1(CActor::Update(fTime));
fTime is a valid floating point value in the method which calls this algorithm. This does not compile! I tried a variety of alternatives but none compile. Any suggestion on how to compile this?
Jurgen
|
|
|
|
|
Try with
for_each(...begin(), ...end(), bind2nd(mem_fun(CActor::Update),fTime));
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Is there anyone that knows why the following piece of code does not work as it's supposed to?
void CStomGraphDlg::OnSelectMonthcalendar(NMHDR* pNMHDR, LRESULT* pResult)
{
COleDateTime dtSel;
if(m_ctlMonthCalendar.GetCurSel(dtSel)!=0)
{
MessageBox(dtSel.Format("%x"));
// set current selection
GetDlgItem(IDC_STATIC_SEL)->SetWindowText(dtSel.Format(_T("%x")));
}
else
{
MessageBox(_T("Error getting current selection"), _T("Error"), MB_OK|MB_ICONERROR);
}
*pResult = 0;
}
It is supposed to return the date selection in COleDateTime format but the only time it works is after the program has just started, and you select the current date. After changing the selection it crashes and returns invalid date format or something. GetCurSel should return the selection date, right?
Any help appreciated,
Deian
|
|
|
|
|
Deian,
Have a look at this Same problem I perhaps? Only way I could get round it was with GetCurSel( LPSYSTEMTIME pDateTime ) which seemed to return the right result.
Adam.
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
Thanks, I will try that solution ))
Greetings,
Deian
|
|
|
|