|
if(v1) { v2 = 0; }
else { v2 = 1; } runs a little faster than
v2 = v1 ? 0 : 1;
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote:
if(v1) { v2 = 0; }
else { v2 = 1; }
runs a little faster than
v2 = v1 ? 0 : 1;
How thats run Faster?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
About four years ago I did some test about your question with VC++6. Just now I did again with VC++7.1. My method is as:
void Test_If(bool& v1, int& v2)
{
if(v1) {
v2 = 0;
}
else {
v2 = 1;
}
}
void Test_Op(bool& v1, int& v2)
{
v2 = v1 ? 0 : 1;
}
void CTestComboDlg::OnBnClickedButton1()
{
bool v1 = true;
int v2 = 3;
int i;
DWORD ds, de;
ds = GetTickCount();
for(i = 0; i < 0x10000000; i++) {
Test_If(v1, v2);
}
de = GetTickCount();
TRACE("IF: %u \n", de - ds);
ds = GetTickCount();
for(i = 0; i < 0x10000000; i++) {
Test_Op(v1, v2);
}
de = GetTickCount();
TRACE("OP: %u \n", de - ds);
} The output is:
IF: 48690
OP: 52576
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote:
he output is:
IF: 48690
OP: 52576
Nice, Thanks for same
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ThatsAlok wrote:
How thats run Faster?
maybe because it has to evaluate the ?: operator before.
1. using if :
- evaluate the condition.
- test the if statement
- assign v2
2. using ?: :
- enters the = operator
- enters the ?: operator
- evaluate the condition
- return the right parameter wether the condition is true or false
- assign v2
i feel it like this... but i personnally still use the second case
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You should not have to feel a thing.
Just DO IT by examining the disassembly.
The assembly dump would explain why one is faster than the other.
|
|
|
|
|
In my dialog based program the Mainmenus underscore symbols not appearing by default. If I pressed alt key then only they are apearing. I want to make my menu should show shortcut keys like VC++ editor shows. with out pressing alt key I want to show shortcut keys. Any help please. My OS is XP.
Nice talking to you.
|
|
|
|
|
Maybe you forgot to place the ampersand before the character that you want to be underlined
|
|
|
|
|
Sorry, I kept it. My application is working fine in other os. like Windows - 2000, NT. But not in XP.
Nice talking to you.
|
|
|
|
|
G Haranadh wrote:
If I pressed alt key then only they are apearing
That's the default behavior in XP. You can change it in Control Panel - Display - Appearance - Effects - Hide underlined letters for keyboard navigation until I press the Alt key.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
The actual problem is I could not satisfy all clients by saying, disable this behavior. I have to disable programatically particularly to my application. It should not effects other applications. Can we do this? Thank you for replying.
Nice talking to you.
|
|
|
|
|
G Haranadh wrote:
The actual problem is I could not satisfy all clients by saying, disable this behavior.
Why not? It's a system setting, and applications are expected to respect those settings, not to override them. The same goes for fonts, colors, sizes, etc.
I can understand some client may want to always see the underlines, but then he probably also want to see them in all the applications he use, so changing it at the system level is what he needs.
What am I missing?
That being said...
G Haranadh wrote:
Can we do this?
It may be possible, but I don't know how or at what cost...
G Haranadh wrote:
Nice talking to you
Same here.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
CStrings are used to declare string, right. But what if I want to check for the individual contents of the string. In Turbo C, strings are declared as char myString[10]; wherein you can access every single character in the string by ch = myString[5];
How will I going to be able to do it in Visual C++? coz if I used CString as a variable type, myString[5] is an error.
|
|
|
|
|
CString has an operator[] to access individual characters, although it is read-only.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
"Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"
-- Rico Mariani, CLR perf guy
|
|
|
|
|
thanx,.,. ok, then do i have to use char myString[max] or is there another variable type that I could use?
|
|
|
|
|
You can use the member function CString as GetAt().
For eg.,
CString strName;
strName.GetAt(0);
strName.GetAt(1);
....
....
....
You can use GetLength() function of CString and loop through all the characters.
Regards,
Neelesh K J Jain.
Don't Forget to Rate the replies when they help you.
|
|
|
|
|
Is strName.GetAt(1) a read-only or I can also assign characters to them?
|
|
|
|
|
There's a corresponding SetAt function.
CString members
He is smart. He will make our Windows go.
|
|
|
|
|
|
Its a read-only, for assigning characters at a particular location, use SetAt() member function.
Don't forget to rate the replies which helps you.
|
|
|
|
|
benjnp wrote:
How will I going to be able to do it in Visual c++
What about CString::GetAt(..)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I created a dialog-based MFC project, I inserted a menu on the resources and put some items. I was able to place commands on the items on the menu but the shortcut keys aren't working at all. I've inserted an Accelerator on the resources and placed the shortcut keys but again the shortcut keys (ctrl+_) aren't working. Did I miss something? Bcoz shortcut keys are working when I created SDI in MFC project.
|
|
|
|
|
|
I tried the link but my program now closes because of an error. It started to run but a warning message saying that it has an error then it will be closed.
Is there any other way on how to place a shortcut on a dialog-based MFC project?
|
|
|
|
|
Hello Friends,
I am having a problem with the ToolBar Control of my SDI application.
I am having few buttons and in between one combo box. I am trying to delete one button before combobox at runtime based on satisfying a condition.
I am able to Hide the button, but all the other buttons on its right hand side are moving, but the combo box is not moving at all due to which the button next to the combobox is getting overlapped by combobox.
Please help to overcome the above problem. Its very important for me to work this one.
Thanks alot in Advance.
Neelesh K J Jain.
|
|
|
|