|
While you can do nothing about the 15ms delay, see if this article is of any help with serial ports in general.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello everyone,
i am trying to compile my program where i am using the functions like sqrt pow and fabs. I do have math.h included but for some reason i get errors like:
error C2668: 'fabs' : ambiguous call to overloaded function
same for the rest of the functions
i have this included:
#include "stdafx.h"
#include "math.h"
i tried including <cmath> but still same errors.
Does anyone know why they are not being recognized?
my file is .cpp not .c but it is an MFC project.
thanks
|
|
|
|
|
It's because those functions are overloaded for several types: float, double and long double. Thus, if you pass in an integer, the compiler doesn't which one to choose. An easy fix is to simply pass a double (multiply what you pass in by 1.0), this should fix the problem.
int result = (int)fabs(value*1.0);
|
|
|
|
|
Cedric Moonen wrote: int result = (int)fabs(value*1.0);
Better could be
int result = (int)fabs((double)value);
Because it avoids a multiplication. Am I right?
- ns ami -
|
|
|
|
|
Yes you're right. It's just because I am used to multiply by 1.0 because in general I use that in calculation (where I don't want to put a cast inside because it looks ugly)
|
|
|
|
|
ns ami wrote: Am I right?
Only if the code were in a huge loop would the difference in time even be noticeable.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
it won't matter at all. the multiplication will be optimized away, and the two different calls will end with exactly the same object code.
|
|
|
|
|
nevertheless it's a bad style as many people won't understand it.
Don't try it, just do it!
|
|
|
|
|
the compiler will optimize that multiplication away.
int value = rand();
int result1 = (int)fabs(value*1.0);
printf("%d, %d\n", result1, result1);
VC6, release mode gives the following assembly:
; 10 : int value = rand();
call _rand
; 11 : int result1 = (int)fabs(value*1.0);
mov DWORD PTR -4+[esp+4], eax
fild DWORD PTR -4+[esp+4]
fabs
call __ftol
; 12 : printf("%d, %d\n", result1, result1);
push eax
push eax
push OFFSET FLAT:??_C@_07JPPP@?$CFd?0?5?$CFd?6?$AA@ ; `string'
call _printf
no fmul.
if you do this:
int value = rand();
int result1 = (int)fabs((double)value);
printf("%d, %d\n", result1, result1);
you get this:
; 10 : int value = rand();
call _rand
; 11 : int result1 = (int)fabs((double)value);
mov DWORD PTR -4+[esp+4], eax
fild DWORD PTR -4+[esp+4]
fabs
call __ftol
; 12 : printf("%d, %d\n", result1, result1);
push eax
push eax
push OFFSET FLAT:??_C@_07JPPP@?$CFd?0?5?$CFd?6?$AA@ ; `string'
call _printf
exactly the same.
|
|
|
|
|
Chris Losinger wrote: the compiler will optimize that multiplication away.
Thank you for pointing out that...
- ns ami -
|
|
|
|
|
i need alternative code for CMap is it possible to implement my own CMap wrapper Class using the STL::map
Hi this Ravinder
|
|
|
|
|
I don't really understand your question but a std::map is an alternative for the MFC CMap (in fact, I much prefer the STL containers than the MFC containers).
|
|
|
|
|
... in addition, perhaps the biggest difference is that CMap uses hashing for its keys, and std::map uses key comparisons to store them in some sorted order.
--
Arman
|
|
|
|
|
Need the wrapper class for CMap using the STL map(Because i have some problems using CMap i want the same functionality of CMap but internally i have to use map)
Hi this Ravinder
|
|
|
|
|
So you need the interface of CMap and the implementation of std::map..? If so, then you need to declare your own CMyMap with an std::map member variable declared in it, and try to implement CMap similar functions in your CMyMap. However, you cannot simulate hash code related functions of CMap via a std::map..
Did I understand your problem correctly?
--
Arman
|
|
|
|
|
Hi All,
How to get the available ports for serial port communcation.
Thanks & Regards,
Anitha
|
|
|
|
|
You can use CP article Search engine..
See here[^]. I hope it helps.
Regards,
Sandip.
|
|
|
|
|
Check out the Win32_SerialPortConfiguration and Win32_SerialPort WMI classes.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I am just curious to know if there is a way to find the HWND of a window, given no actual window title and no definitive process name. Although I could get a handle by using the process name, I'd rather not since users might rename the executable file to something else.
I am attempting to prevent two instances of one app from being run at once, so I stuck a mutex in. I want my app to send a message to the already running program and close. However, my app needs the HWND of the other running app to send a message to it with SendMessage. The problem is, my app does not have an actual "window", meaning that I can't get it's HWND with FindWindow. It's derived from CFrameWnd and doesn't show up in taskmgr (FindWindow).
Any suggestions on how to accomplish this? Thanks in advance
|
|
|
|
|
How about saving the HWND into a registry location?
«_Superman_»
|
|
|
|
|
That'd actually be a good idea.
I'll try that. But is there any more...elegant..way to do this?
|
|
|
|
|
What about using events..??
Regards,
Sandip.
|
|
|
|
|
Rather than a mutex (which I'm presuming has a unique name), you could have a uniquely named bit of shared memory, in which the first process to run could store things like the HWND to post a message to?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I'm probably going with this idea. Thanks a lot.
|
|
|
|
|
Hi,
I was wondering what is the order of API calls to replace a peice of text in a Rich Edit Control Dialog
I do the following
WM_SETSEXT to send the Text the Rich Edit Dialog BOX
The EM_SETSEL 0,7 setting the selection for char 0 - 7
Then doing the SetCharFormat to set the Character fromat to red
memset( &cf, 0, sizeof cf );
cf.cbSize = sizeof cf;
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
SendMessage(RichWindow,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM) &cf);
Then the replacement text
strncpy(addr,"00000000",8);
SendMessage(RichWindow,EM_REPLACESEL,TRUE,(LPARAM) addr);
However more then 8 charcters are replaced seeems like 9 or 10
|
|
|
|