|
Maxwell Chen is right. The result should be 100.
Post-Increment means "Increment this variable after the operation the post-increment is used in".
So a = b++ means "A = B. Increment B."
and a= b++ * c++ means "A = B multiplied with C. Increment B. Increment C."
Cheers
Sebastian
|
|
|
|
|
u know * is Preeminent than ++ so at first RESULT will set to (Var * Var).
but var++ will not change the result
so result = (10*10) = 100
and val will updated to 12
|
|
|
|
|
You might be confused...
Regarding to the example:
cout << (var++ * var++);
The meaning of "precedence" is, to take the expression as:
cout << ((var++) * (var++));
// Means that parsing the postfix ++ token first.
// Not means that counting the result of postfix ++ operation.
rather than
cout << ((var++) (*var)++); // Wrong.
since operator * (Multiplicative) has lower precedence than operator ++ (postfix).
<b>Maxwell Chen</b>
|
|
|
|
|
Ok I see. You are right, sorry about the confusion.
|
|
|
|
|
Maxwell Chen
|
|
|
|
|
C++ only guarantees that all side-effects are complete by the point that a sequence point is reached.
All function arguments must be evaluated before a function is called, but order of evaluation of the function arguments is implementation-defined. Visual C++ clearly evaluates var once, then performs the multiplication, then the post-increments. This looseness allows the compiler to produce more optimal code in some circumstances.
C# and Java have strict left-to-right evaluation, so your code does work as you are expecting with those languages.
|
|
|
|
|
nicely explained but i am still not completely satisfied just because when i implement my own class "myint" which has the post increment, the multiplication and the assignment operators overloaded and i use them as:
myint a(10);<br />
myint c=(a++ * a++);
i get value of c as 110
but when i use int i.e:
int a=10;<br />
int c=(a++ * a++);
i get c as 100
why this???
secondly in the case of cout<<(a++ * a++) u can say that (a++ * a++) comes under the case of "evaluation of function order" (though i don't agree) but when we use
int c=(a++ * a++) ;
it does not come under "evaluation of fuction order" it comes under "operator precedence" case, and it seems as if vc++ is voilating some rules.
for ur information the "evaluation of function order" case is as:
int a=1;
cout<
|
|
|
|
|
The C++ standard (ISO 14882:1998) at section 5, paragraph 5 reads:
Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored. The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined.
Example:
i = v[i++];
i = 7, i++, i++;
i = ++i + 1;
i = i + 1; All that C++ guarantees is that the side-effects of evaluating an expression are complete by the next sequence point - it does not specify an order of evaluation of terms in an expression, except where operator precedence is involved. The second example above works because the comma operator introduces a sequence point.
The exact text in the standard regarding sequence points is in section 1.9, paragraph 7, and reads: Accessing an object designated by a volatile lvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression might produce side effects. At certain specified points in the execution sequence called sequence points, all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place.
However, an overloaded operator is treated in the same way as a function call. There is a sequence point between evaluating the arguments for a function call and the actual call itself, and at the end of each statement. In the case of myint , the compiler essentially generates:
myint c = (a.operator++(int)).operator*(a.operator++(int)); The two calls to operator++ are therefore executed before the call to operator* .
In the second case I would argue that the compiler appears to have generated the wrong code, because function calls are being generated, and << is left-associative. Again, the mapping is something like:
((cout.operator<<(a++)).operator<<(a++)).operator<<(a++) I would have expected the side-effect of the first increment to be complete before the second argument was evaluated. However, this is where my understanding of the standard becomes a bit hazy. If you want a genuine expert, ask on the comp.lang.c++.moderated newsgroup. All I can tell you is that Visual C++ 6 and Visual Studio .NET 2003 agree in a Debug build. For a release build, VC6 outputs "321"; VC7.1 outputs "111".
|
|
|
|
|
Modifying var more than once between sequence points results in undefined behavior in C++. A C++ compiler can generate whatever results it wants from this. You could get 100, 110, 121, or any other value. Any result produced can't be considered correct or wrong - it is undefined.
|
|
|
|
|
if the program is:
int var = 10;
cout<<(var++ * var++);
the result is 102
and if the program is like this:
int var = 10;
cout<<((var++)*(var++));
the result is 100;
what i think is first the mutiplication operation is being taken place and the varible is getting incremented.
in vc++ programming guide present in MSDN library
unary operator (post increment) has the highest precedence
ok
u know the problem y it is happening
pls send a mail
|
|
|
|
|
Grey the background of a CListBox on the selection of a button,
Currently using WM_CTLCOLOR returing diff brushes work. But I have the style Extended for the ClistBox. with this style. when I grey out the list, if the list has items it wil grey only that part of the list that is empty. The filled part still has the Background as white
The below code will work for Single selection style, but not for extended style.
HBRUSH CTestaDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
//Set background transparent
pDC->SetBkMode(TRANSPARENT);
if (pWnd->GetDlgCtrlID() == IDC_MYLISTBOX)
{
if(m_bGrayed)
return (HBRUSH)GetStockObject(GRAY_BRUSH);
else
return (HBRUSH)GetStockObject(WHITE_BRUSH);
}
return hbr;
}
void CTestaDlg::OnRadio1()
{
m_bGrayed = FALSE;
m_MyListBox.EnableWindow(TRUE);
}
void CTestaDlg::OnRadio2()
{
m_bGrayed = TRUE;
m_MyListBox.EnableWindow(FALSE);
}
|
|
|
|
|
i need to know how to share on Dll with multiple client
any link or tutorial which focus on these isuue would be appreciated
thanx
|
|
|
|
|
Do you have access to the DLL code. If yes i cud give u pointers.
Else try to find out if the dll is thread safe where multiple client can access it
Dimple
|
|
|
|
|
Thanx 4 reply dimple
i refered one book where i read,u can share the dll with memory mapping to access multiple client
like
#pragma dat_seg()
but i no idea how to implement that one.
can give me some idea
thanx
|
|
|
|
|
this sounds real interesting let me know how u do it if u do get the answer.
in my case i had to add a class to the dll code & create objects for each new client & maintain a map of those objects
|
|
|
|
|
|
Ok I know I can get an EditBox to respond to a double click message by providing a function in a derived CEdit class.
But what I really want is for my Dialog class to know when the edit box recieves a double click message like it does when the ON_EN_CHANGE message is sent, but so far I'm un sure of how to do this.
Any assistance would be great, thanks.
class CMyEdit : public CEdit
{
public:
CMyEdit(){};
//{{AFX_VIRTUAL(CMyEdit)
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(CMyEdit)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
//{{AFX_MSG_MAP(CMyEdit)
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CMyEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CEdit::OnLButtonDblClk(nFlags, point);
}
class CMyPage : public CDialog
{
public:
CParticle2Page(CWnd* pParent = NULL); // standard constructor
virtual ~CParticle2Page();
enum { IDD = IDD_PARTICLE2DLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEnChangeMyEdit();
afx_msg void OnDBClickedMyEdit();
CMyEdit m_MyEdit;
}
CMyPage::CMyPage(CWnd* pParent /*=NULL*/)
: CDialog(CMyPage::IDD, pParent)
{
}
void CMyPage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MY_EDIT, m_MyEdit);
}
BEGIN_MESSAGE_MAP(CMyPage, CDialog)
ON_EN_CHANGE(IDC_MY_EDIT, OnEnChangeMyEdit)
ON_WM_LBUTTONDBLCLK(IDC_MY_EDIT, OnDBClickedMyEdit)
END_MESSAGE_MAP()
void CMyPage::OnEnChangeMyEdit()
{
int a = 10;
}
void CMyPage::OnDBClickedMyEdit()
{
int a = 10;
}
|
|
|
|
|
i download the divx 5.1.1 from the divx.com web site.
it has only the decode,but i want the encode.
who can tell me where to get?
or i must to write the encode of myself.
if i DIY,
how i do?
thx!!
hxr601
|
|
|
|
|
Download virtuaDub.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I have this program, and I need to find the difference between the start time and end time. My code:
<br />
#include <iostream.h><br />
#include <iomanip.h><br />
<br />
class StopWatch<br />
{<br />
public:<br />
StopWatch(float hour, float minute, float second);<br />
StopWatch();<br />
void difference(StopWatch start_time, StopWatch end_time);<br />
int get_hour();<br />
int get_minute();<br />
int get_second();<br />
int reg_time();<br />
int mil_time();<br />
private:<br />
int hour, minute, second;<br />
<br />
};<br />
<br />
void main()<br />
{<br />
int start_time, end_time;<br />
char chr;<br />
int difference;<br />
cout << "This program is a stop watch program. It will store time in hours, minutes, and seconds" << endl;<br />
do<br />
{<br />
StopWatch start_time, end_time, mil_time, reg_time;<br />
cout << "Enter Start Time" << endl;<br />
start_time.get_hour();<br />
start_time.get_minute();<br />
start_time.get_second();<br />
<br />
cout << "Enter End Time" << endl;<br />
end_time.get_hour();<br />
end_time.get_minute();<br />
end_time.get_second();<br />
<br />
cout << "In Military Time" << endl;<br />
cout << " Start Time Entered: ";<br />
start_time.mil_time();<br />
cout << " End Time Entered: ";<br />
end_time.mil_time();<br />
<br />
cout << "In Regular Time" << endl;<br />
cout << " Start Time: ";<br />
start_time.reg_time();<br />
cout << " End Time: ";<br />
end_time.reg_time();<br />
<br />
difference(start_time, end_time);<br />
cout << "Do you wish to enter another time(Y/N)?" << endl;<br />
cin >> chr;<br />
if(chr != 'N' && chr != 'n' && chr != 'Y' && chr != 'y')<br />
{<br />
cout << "Enter Y or N" << endl;<br />
}<br />
}while (chr == 'Y' || chr == 'y');<br />
<br />
<br />
} <br />
<br />
StopWatch::StopWatch(float hours, float minutes, float seconds)<br />
{<br />
hour = hours;<br />
minute = minutes;<br />
second = seconds;<br />
}<br />
<br />
StopWatch::StopWatch() : hour(0), minute(0), second(0)<br />
{<br />
}<br />
<br />
int StopWatch::get_hour()<br />
{<br />
cout << " Hour: ";<br />
cin >> hour;<br />
return hour;<br />
}<br />
<br />
int StopWatch::get_minute()<br />
{<br />
cout << " Minute: ";<br />
cin >> minute;<br />
return minute;<br />
}<br />
<br />
int StopWatch::get_second()<br />
{<br />
cout << " Second: ";<br />
cin >> second;<br />
return second;<br />
}<br />
<br />
int StopWatch::reg_time()<br />
{<br />
<br />
cout << setfill('0') << setw (2) << hour << ":" << setw (2) << minute << ":" << setw(2) << second;<br />
if(hour < 12)<br />
cout << " AM";<br />
else<br />
cout << " PM";<br />
cout << endl;<br />
<br />
return 0;<br />
}<br />
<br />
int StopWatch::mil_time()<br />
{<br />
cout << setfill('0') << setw (2) << hour << ":" << setw (2) << minute << ":" << setw(2) << second << endl;<br />
return 0;<br />
}<br />
<br />
void difference(StopWatch start_time, StopWatch end_time)<br />
{<br />
cout << "difference = " << start_time.get_hour() - end_time.get_hour() << " hours, " << start_time.get_minute() - end_time.get_minute() << " minutes, " << start_time.get_second() - end_time.get_second() << " seconds" << endl;<br />
<br />
}<br />
It is the last function I need help with... well calling it anyways. I'm just not sure how to do it.
|
|
|
|
|
You would do better for your difference function to return a value that is validly in 0-60 minutes and seconds every time. You would also do better to return the time as a structure that you define, and providing an operator << for it, so that it can then be sent to cout. This class is not very useful or reuseable. I know it's you're homework, but still, best learn good principles now.
And that includes not asking broad homework questions. I presume the trouble is that you're getting gaps with negatives in them ? Just think about what it is you need to do to work around that, it's not hard.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
if the user enters 25 and more or the user enters -ve values for hours,the program will not prompt any error message
and to find the difference, write a function where all the hours ,minutes and sec are compared with 59 mins , 59 secs convert to next hours
and think ur logic
bye
thennati
|
|
|
|
|
how can I make a simple assembly compiler so it would use basic functionality and actually compile the code, maybe a website or tutorial
Actual Linux Penguins were harmed in the creation of this message.
|
|
|
|
|
Try NetWise ASM (NASM) ...
Maxwell Chen
|
|
|
|
|
Hello,
I have inherited a GUI application that I am required to modify. One of the modifications that I have already implemented consists of capturing a serial data stream, doing some processing on it, and then writing it out to a file.
The serial data is captured in a separate reader thread that signals the main dialog window when serial data is ready to be processed. This all works fine. The serial data stream consists of many voltage and temperature measurements collected from an attached A/D converter box. I parse the A/D data and keep track of the latest temperature and voltage measurements for all 22 channels that we are sampling.
I would like to modify the main GUI display to also show the latest values of some if not all of the 22 channels that we are monitoring. In the simplest implementation, I could have a list down one side of a form that shows:
Variable 1: 22.876 Volts
Variable 2: 76.988 Degrees
.
.
.
Variable 22: 23.988 Volts
To the right of each of these text labels I would like to have a small "window" where I could write the most recent value received for each of the data channels, be it tempearture or voltage. This way, the operator could see all the current data value on a single screen.
The problem is that I have been looking through the Toolbox and there doesn't appear to be any sort of "box" structure that could be used for this purpose. Maybe I'm just missing it. Could someone please point me in the right direction. Perhaps there is a sample project that someone has done that would allow for a new tool like this?
A second question revolves around going one step further. Since I am collecting this data over time, it would be nice to show the user say the last 10 minutes of data for any given variable in a "graph window", for lack of a better term. Does anyone have any links to a "graph tool" that I could use that might enable me to display my collected data in a graphical format in addition to the text display I mentioned earlier?
Thanks,
Robert
|
|
|
|
|