Click here to Skip to main content
15,889,200 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionbeginner, simple c question. Pin
antionette15-Jan-10 4:39
antionette15-Jan-10 4:39 
AnswerRe: beginner, simple c question. Pin
Richard MacCutchan15-Jan-10 4:45
mveRichard MacCutchan15-Jan-10 4:45 
GeneralRe: beginner, simple c question. Pin
Chris Losinger15-Jan-10 5:11
professionalChris Losinger15-Jan-10 5:11 
GeneralRe: beginner, simple c question. [modified] Pin
Richard MacCutchan15-Jan-10 5:38
mveRichard MacCutchan15-Jan-10 5:38 
JokeRe: beginner, simple c question. Pin
loyal ginger15-Jan-10 4:58
loyal ginger15-Jan-10 4:58 
GeneralRe: beginner, simple c question. Pin
dxlee15-Jan-10 5:13
dxlee15-Jan-10 5:13 
AnswerRe: beginner, simple c question. Pin
CPallini15-Jan-10 5:05
mveCPallini15-Jan-10 5:05 
AnswerRe: beginner, simple c question. Pin
Chris Losinger15-Jan-10 5:07
professionalChris Losinger15-Jan-10 5:07 
antionette wrote:
i+j=?


that's actually a tricky question. there are a lot of (really strange and non-intuitive, IMO) rules about how mixed signed/unsigned math is done in C. and a lot of those rules depend on how your compiler interprets the standard, and which standard.

i've found that whenever i'm doing signed/unsigned arithmetic, it's best to cast everything to a signed value, then perform the arithmetic. if the result needs to be unsigned, then i range-check the value to make sure it's non-negative and small enough to fit the result.

in this case, the answer is a huge positive integer.

int i = -20;
unsigned  j = 10;
__int64 k = i + j;


k = 4294967286


modified on Friday, January 15, 2010 11:22 AM

GeneralRe: beginner, simple c question. Pin
Richard MacCutchan15-Jan-10 6:55
mveRichard MacCutchan15-Jan-10 6:55 
JokeRe: beginner, simple c question. Pin
CPallini15-Jan-10 8:36
mveCPallini15-Jan-10 8:36 
QuestionIndex of rows in report view list control with groups enabled is random order Pin
Keith Worden15-Jan-10 2:49
Keith Worden15-Jan-10 2:49 
AnswerRe: Index of rows in report view list control with groups enabled is random order Pin
Richard MacCutchan15-Jan-10 4:50
mveRichard MacCutchan15-Jan-10 4:50 
GeneralRe: Index of rows in report view list control with groups enabled is random order Pin
Keith Worden15-Jan-10 5:29
Keith Worden15-Jan-10 5:29 
GeneralRe: Index of rows in report view list control with groups enabled is random order Pin
Richard MacCutchan15-Jan-10 6:48
mveRichard MacCutchan15-Jan-10 6:48 
GeneralRe: Index of rows in report view list control with groups enabled is random order Pin
Keith Worden15-Jan-10 7:00
Keith Worden15-Jan-10 7:00 
GeneralRe: Index of rows in report view list control with groups enabled is random order Pin
Richard MacCutchan15-Jan-10 7:21
mveRichard MacCutchan15-Jan-10 7:21 
GeneralRe: Index of rows in report view list control with groups enabled is random order Pin
Keith Worden15-Jan-10 7:31
Keith Worden15-Jan-10 7:31 
QuestionOne Doubt Pin
ashwath197915-Jan-10 2:48
ashwath197915-Jan-10 2:48 
AnswerRe: One Doubt Pin
Maximilien15-Jan-10 2:55
Maximilien15-Jan-10 2:55 
GeneralRe: One Doubt Pin
ashwath197915-Jan-10 17:23
ashwath197915-Jan-10 17:23 
AnswerRe: One Doubt Pin
CPallini15-Jan-10 2:56
mveCPallini15-Jan-10 2:56 
AnswerRe: One Doubt Pin
LunaticFringe15-Jan-10 2:58
LunaticFringe15-Jan-10 2:58 
AnswerRe: One Doubt Pin
CODEPC15-Jan-10 5:16
CODEPC15-Jan-10 5:16 
QuestionExtracting information from Win32 Dll in C/C++ Pin
glitteringsound15-Jan-10 1:28
glitteringsound15-Jan-10 1:28 
AnswerRe: Extracting information from Win32 Dll in C/C++ [modified] Pin
Adam Roderick J15-Jan-10 1:37
Adam Roderick J15-Jan-10 1:37 

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.