David's question was perfectly valid btw, since I've yet to run into any sort of architecture either where integer rollover results in a zero value.
I've never encountered one either, although drrck is at least partially correct about integer overflows - they cause undefined behaviour (not implementation-defined behaviour) for signed integer types (but not unsigned types).
K&R states: "The handling of overflow, divide check, and other exceptions in expression evaluation is not defined by the language. Most existing implementations of C ignore overflow in evaluation of signed integral expressions and assignments, but this behavior is not guaranteed."
The C standard (ISO/IEC 9899:1999, section 6.5, paragraph 5) states: "If an exceptional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined." but also clarifies that "A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type."
Having said that, in this case we're not talking about overflow, but rather the conversion of a value that can't fit into the target type - and that is implementation-defined:
"A conforming implementation of ISO C is required to document its choice of behavior in each of the areas that are designated "implementation defined." The following lists all such areas, along with the section number from the ISO/IEC 9899:1999 standard."
And later: "The result of, or the signal raised by, converting an integer to a signed integer type when the value cannot be represented in an object of that type (6.3.1.3)."
Simply answering the question would have saved at least two of us the time, and shared some knowledge with others. Isn't that what we're all here for in the end?
Apparently, that's what all of us except Drrck are here for, he's here to prove to the world that he's the foremost expert on everything code related because he says so rather than because he's got sources for his information nor because he can demonstrate in any way that others could appreciate… just because he told us so.
I was always taught that when involved in a debate and the other person asked for a citation of where your data or argument was coming from/based upon, it generally invalidated your data/argument if you refused to provide either the citation or a reasonable explanation of why you couldn't. In this case at least three of us blatantly asked for his source (and I'm not even addressing other threads at the moment where he's done the same thing but even worse) and he accused the first of being a "die-hard skeptic", the second of being a "trolling cheer-leader" "just to be on the bandwagon", and completely ignored the third. I'm ready to call "Bullshit" with noted exception made for KaVir's comments in the post before this one.
I'm curious as to the reason for the strange output. If there does indeed exist a system where an overflow would result in a 0 value, one in which is, or could be, used by MUD administrators, that information would be nice to know as well.
Now, if I were to say "Yay! Go, drrck!" would I be a cheer-leading troll, or would I be cheer-leading the troll? :smirk:
Well we are waiting for the entire function.. otherwise there isnt much anyone can do..
23 Feb, 2008, David Haley wrote in the 31st comment:
Votes: 0
The entire function, or a report on setting a breakpoint in gdb, or a report on running valgrind, or … as syn says we're really just stuck for now. :wink:
I asked him to post the entire function earlier on, we can speculate all we want on what exactly is going on but it does no good without the function itself. Someone is bound to spot some kind of weirdness and go "AHA!" after seeing it.
Sorry for such a gap in my posting, just got extremely busy with a residency course I'm stuck in for work right now that everything else went back burner on me. I actually just remembered this today!
I've placed the entire function up at http://games.gotr00t.us/vortex/files/voi... for anybody who wishes to look at it. This weekend I'll try to make time to swap the arguments to sprintf per suggestion and see if that makes any difference. I've gone through Valgrind I don't know how many times just looking to fix errors and optimize where I can throughout the game and it has never specifically thrown errors from this function.
Thanks for all the assistance, despite my sorely lacking in participation :P
04 Mar, 2008, David Haley wrote in the 35th comment:
Votes: 0
Hmm, this function is big enough that it's hard to just eyeball it and see what's going on. The only real way to help at this point I think would be to have access to the whole running system to be able to look at the gdb output – either that or you'd provide the output for us to look at.
Well from what I can tell, prior to reaching the point where it's displaying the 0 value, these are the only calculations done on the "statcap" integer:
Hmm, this function is big enough that it's hard to just eyeball it and see what's going on. The only real way to help at this point I think would be to have access to the whole running system to be able to look at the gdb output – either that or you'd provide the output for us to look at.
Is there a rough primer available someplace on good use of GDB BP's? I'll happily go along with that if it's needed. My GDB knowledge is about limited to playing with cores to figure out where I broke something badly :)
syn said:
I wonder which godwars base that came out of.
I want to say Dystopia X-Mas? The one previously used was quite the eyesore and hard to modify…So why re-invent the wheel? Just find a working one and edit accordingly :)