Click here to Skip to main content
15,890,506 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Application crashes only in release mode (possible heap/stack corruption) Pin
Luc Pattyn9-Dec-10 13:16
sitebuilderLuc Pattyn9-Dec-10 13:16 
GeneralRe: Application crashes only in release mode (possible heap/stack corruption) Pin
XTAL2569-Dec-10 17:48
XTAL2569-Dec-10 17:48 
GeneralRe: Application crashes only in release mode (possible heap/stack corruption) Pin
Luc Pattyn9-Dec-10 22:47
sitebuilderLuc Pattyn9-Dec-10 22:47 
GeneralRe: Application crashes only in release mode (possible heap/stack corruption) Pin
XTAL2569-Dec-10 23:21
XTAL2569-Dec-10 23:21 
AnswerRe: Application crashes only in release mode (possible heap/stack corruption) Pin
Rajesh R Subramanian9-Dec-10 17:26
professionalRajesh R Subramanian9-Dec-10 17:26 
AnswerRe: Application crashes only in release mode (possible heap/stack corruption) Pin
XTAL25612-Dec-10 12:09
XTAL25612-Dec-10 12:09 
QuestionC Casting Problem Pin
Andy2029-Dec-10 8:14
Andy2029-Dec-10 8:14 
AnswerRe: C Casting Problem Pin
Luc Pattyn9-Dec-10 9:01
sitebuilderLuc Pattyn9-Dec-10 9:01 
I think it works like this:

the latitude in degrees ranges from -90 to +90 (and not -180 to +180).
the encoding used is 32-bit fixed integers with an implied scale factor, so the full range [-90,+90] gets mapped onto the full integer range.
So you want +90 represented by the largest positive 32-bit integer (which equals 2^31 minus one, or 0x7FFFFFFF), hence:
int fixed32(double lat) {
    lat=lat/90.;
    lat=lat*0x7FFFFFFF;
    return (int)lat;
}


Notes:

1. this code will never return the minimum value (0x80000000). For -90 it results in 0x80000001 which is a consequence
of [-90,+90] being symmetric around zero, whereas the integer range [0x80000000, 0x7FFFFFFF] isn't.

2. I tend to avoid magic constants, such as the 4.65661287307739E-10 you had. I prefer to write them in a way that reveals what they stand for. Your value stems from 1.0/0x7FFFFFFF

3. I doubt the code you have shown would crash at all.
lat/(BEARING_SCALING * 180) will not exceed the acceptable range for integers (and your formula being wrong by a factor of 2 IMO only reassures this).
(positionData.msgPosLat) * BEARING_SCALING * 180) may incur an integer overflow (again due to the factor of 2), but normally those get swallowed.
So I expect if anything bombs, it must be the code that follows after you used these formulas, mainly the latitude going all the way up to +180.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.

modified on Thursday, December 9, 2010 3:45 PM

GeneralRe: C Casting Problem Pin
Andy2029-Dec-10 10:41
Andy2029-Dec-10 10:41 
GeneralRe: C Casting Problem [modified] Pin
Luc Pattyn9-Dec-10 11:06
sitebuilderLuc Pattyn9-Dec-10 11:06 
AnswerRe: C Casting Problem Pin
mbue9-Dec-10 12:07
mbue9-Dec-10 12:07 
QuestionSave image from picturebox use MFC Pin
josipahutar9-Dec-10 8:02
josipahutar9-Dec-10 8:02 
AnswerRe: Save image from picturebox use MFC Pin
mbue9-Dec-10 12:16
mbue9-Dec-10 12:16 
GeneralRe: Save image from picturebox use MFC Pin
tagopi9-Dec-10 17:08
tagopi9-Dec-10 17:08 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar11-Dec-10 7:27
josipahutar11-Dec-10 7:27 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar11-Dec-10 7:38
josipahutar11-Dec-10 7:38 
GeneralRe: Save image from picturebox use MFC Pin
tagopi12-Dec-10 17:08
tagopi12-Dec-10 17:08 
GeneralRe: Save image from picturebox use MFC Pin
josipahutar13-Dec-10 7:29
josipahutar13-Dec-10 7:29 
GeneralRe: Save image from picturebox use MFC Pin
tagopi16-Dec-10 16:45
tagopi16-Dec-10 16:45 
Question890918 - keystroke seems not to generate the desired command Pin
ilostmyid29-Dec-10 6:45
professionalilostmyid29-Dec-10 6:45 
AnswerRe: 890918 - keystroke seems not to generate the desired command Pin
mbue9-Dec-10 12:25
mbue9-Dec-10 12:25 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
ilostmyid210-Dec-10 3:53
professionalilostmyid210-Dec-10 3:53 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
mbue10-Dec-10 8:59
mbue10-Dec-10 8:59 
GeneralRe: 890918 - keystroke seems not to generate the desired command Pin
ilostmyid219-Dec-10 0:38
professionalilostmyid219-Dec-10 0:38 
Questionfull path of a process Pin
zon_cpp8-Dec-10 23:46
zon_cpp8-Dec-10 23:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.