|
I like it
Russell
|
|
|
|
|
Andy202 wrote: I receive a 20 word message and two words of this message define a floating value;
unsigned short message [20]; // Message buffer
e.g. message [2] and message[3] define a float with the mantissa in the lower byte of message[3].
Could I get the floating value by doing this:-
union
{
float data;
unsigned short buff[2];
}convert;
convert.buff[0] = message[2];
convert.buff[1] = message[3];
float val = convert.data;
Or what is the best way to get this 32 bit embedded floating point value.
Andy
Something like that would work if you used the fixes I made in your quote. However, it would be easier to just use
float result = *(reinterpret_cast<float *>(message + 2);
|
|
|
|
|
Thanks, that work great.
Andy.
|
|
|
|
|
Hey guys,
I'm writing a little class that will read data from a file and store it as a string. This data can be either text or a number.
string strHold = csvTable->getValue(row, column);<br />
<br />
char* chHold;<br />
strHold.copy(chHold, strHold.length());<br />
<br />
return atoi(chHold);
I know that atoi() will return a 0 if the value of chHold = "This is not an int," So my question is : what is a good way to check if the zero is actually the number 0 and not a returned zero as the result of atoi("This is not an int").
[Insert Witty Sig Here]
|
|
|
|
|
chHold == "0" ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
so chHold == "0"
would be differnt than
chHold = 0
where "== "0" test for char and "= 0" tests for int?
im going back to c++ 101, its friday morning and im not thinking at all apparently
[Insert Witty Sig Here]
|
|
|
|
|
VonHagNDaz wrote: so chHold == "0"
would be differnt than
chHold = 0
well since the second is an assignment operation.... yeah that's pretty much different.
|
|
|
|
|
come on mike, ive already had a massive brain fart this morning, i dont need you fanning it back at me, the initial wiff was enough...
[Insert Witty Sig Here]
|
|
|
|
|
Ok. more interesting discussion is that very thing is why I prefer to write those type of states as
0 == myvariable;
rather than
myvariable == 0;
if you drop one of the '=' in the first you get a compiler error, in the second you get an assignment operation. Strong Bad.
|
|
|
|
|
led mike wrote: 0 == myvariable;
good tip, thats the first time ive heard that, you may get a few "// - from Mike"'s in my code.
actually there are a lot of thanks to CP members in my code, so dont worry guys, in 20 years when my company is still using the same old code, only hiring straight out of college developers to fix their same old code, and trying to decapitate anyone who wants to modify their old code, you guys will all be immortalized in my comments...
[Insert Witty Sig Here]
|
|
|
|
|
VonHagNDaz wrote: char* chHold;
strHold.copy(chHold, strHold.length());
Shouldn't there be some memory pointed to by chHold ? In any case, it's not needed in the context in which you've shown it. Just convert strHold .
VonHagNDaz wrote: I know that atoi() will return a 0 if the value of chHold = "This is not an int," So my question is : what is a good way to check if the zero is actually the number 0 and not a returned zero as the result of atoi("This is not an int").
Use strtol() instead.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have a static library project that was converted from VS6 to VS2005. The project is set to warning level 4 and to treat warnings as errors. All of the .cpp/.h files compile clean and produce the library fine. I recently started a brand spanking new project and in one of the .cpp files for this new project, when I #include one of the headers from the static lib project, the header file generates the following error
d:\projects\reds\tables\tblport.h(18) : error C2440: 'type cast' : cannot convert from 'const CString' to 'LPCSTR'
The offending line of code is
LPCSTR GetAccountNum() const { return (LPCSTR)m_AccountNumber; }
and the class contains a member called, m_AccountNumber which is declared as type CString.
I thought that there was a cast operator for the CString class that would give you a const pointer? It's like it's there in my converted projects, but not there for anything new. Anyone with a idea of what to look for? Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
|
|
|
|
|
Did you overlook the lacking T in LPCSTR ?
You can not convert a CString to a non-const char* (which is what LPCSTR boils down to without unicode). It can't risk being overwritten without updating its internal bookkeeping.
You can use a CString as a const char* (LPCTSTR ), though.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
But my question still remains. Why does it compile in one project fine, but not compile in another? I've since learned that if I go into the project settings for my new project and turn off inherited settings, whatever they are, then the error goes away. The inherited settings are defining both _UNICODE and UNICODE and it is these two that are causing this problem.
Chris Meech
I am Canadian. [heard in a local bar]
|
|
|
|
|
Humph.
Working with char* but not wchar_t*?
*scratch head*
Well - could it be some strange effect of whar_t being an built-in type or not ("/Zc:whchar_t ")?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
You can't cast a CString to a LPCSTR in a unicode build.
You need to either use generics (LPCTSTR) or if the string MUST be non-unicode,
change the CString to a CStringA type.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark. The new projects are being setup as UNICODE builds and that is what is causing the problem. Once I change the projects to remove the UNICODE definitions, the compile all go fine. For my particular needs, I do not have to be concerned about using UNICODE. Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
|
|
|
|
|
sometimes I got a big suprise by my lovely C++.
here is an example:
class My
{
public:
int i;
public:
void abc()
{
}
};
My my[]=
{
3,
2,
1,
};
code above is correct.
but if I change second public to private for above My class, compile error happened:
error C2440: 'initializing' : cannot convert from 'const int' to 'class My'
why?
|
|
|
|
|
try to put a return 0; inside your void function. What happens?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
aren't you missing a constructor ?
|
|
|
|
|
Your code is working fine in vc8.
|
|
|
|
|
I know that it can works...but I don't like the use of classes as they are structs (it is not everytime true): I prefere to use the constructors to initialize the members.
hope helps
Russell
|
|
|
|
|
Neither do I. I think is better to declare all parameters of a class and give them to void/null values in the constructor and in the destructor of the object, but not only the collections and similars that need to free memory; I do it with everything but simple C-types like int, double.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Russell
|
|
|
|
|
Hi all,
I am getting the followiing error:
error C2146: syntax error : missing ';' before identifier 'PVOID64'
When i am including the PlatformSDK above C:\\DXSDK\\lib i am not getting this error but in that case i am getting the following errors:
c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(305) : error C2065: '_vsnprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(338) : error C2065: '_vsnwprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(5483) : error C2065: 'lstrcpy_instead_use_StringCbCopy_or_StringCchCopy' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(5946) : error C2065: 'lstrcat_instead_use_StringCbCat_or_StringCchCat' : undeclared identifier
Please help me to resolve this.
Regards
|
|
|
|