[ale] OT: c++ datatypes question

J.M. Taylor jtaylor at onlinea.com
Mon Jun 7 14:45:34 EDT 2004


Greetings ale

Got a c++ question that I hope somebody out there in ale-land can help 
with.  It's from my ongoing and getting-very-close-to-finished Palm 
Conduit project, but I don't think any palm knowledge is required for this 
one.

Palm has a datatype WORD which is an unsigned, 16-bit int.  I am trying to
read in a delimited record from a text file into a buffer and assign
what's in the buffer as the value of the variable in question (let's call
it wVar). I cannot change the datatype of wVar. So, ignoring the mechanics
of reading in the value, which works just fine, let's say the buffer I
read into is called tmp.

  wVar = (unsigned short) atoi(tmp);  (or, (unsigned __int16) atoi(tmp))
compiles just fine but dies at runtime.  


  sprintf((char*)wVar,"%u",tmp);
Compiles and doesn't crash at runtime, but I'm getting a zero value which 
isn't right.  Setting the value staticly, like sprintf((char*)wVar,"2")  
gives me a zero value too.

For Palm's DWORD datatype, which is unsigned 32-bit int, all I have to do 
is dwVar = atoi(tmp);  after verifying that tmp isn't null.  So, logic 
dictates that if I cast the incoming buffer to an unsigned 16-bit int, all 
should work as planned.  

Because I am using VisualStudio .NET on W2k, palm's debugger doesn't work
nor does palm's published workaround for the specific debugger problem on
this platform.  Which means at runtime I am completely, totally blind and
just have to flail about hoping that it doesn't crash.  Because I don't
know jack about c, this is causing me great pain.

Thanks as always
jenn

-- 
Jenn Taylor
jtaylor at onlinea.com

------------------------------------------------------------------------
Obviously, a man's judgement cannot be better than the information on which he
has based it.  Give him the truth and he may still go wrong when he has
the chance to be right, but give him no news or present him only with distorted
and incomplete data, with ignorant, sloppy or biased reporting, with propaganda
and deliberate falsehoods, and you destroy his whole reasoning processes, and
make him something less than a man.
-- Arthur Hays Sulzberger




More information about the Ale mailing list