Grum Report post Posted May 3, 2005 Dir[dc].Names[Dir[dc].nf][i]=temp[i++]; a) who is responsible for this piece of beauty? when is i supposed to be incremented, before or after the assignment has taken place? Share this post Link to post Share on other sites
crusadingknight Report post Posted May 3, 2005 (edited) a- O_O Really descriptive variable names, I'm guessing that comes from the browser, and therefore must be sadez's... But I can guarantee it's not mine b- And i is and should be incremented after the assignment, as in almost any assignment of this type... I use that method all the time Edited May 3, 2005 by crusadingknight Share this post Link to post Share on other sites
Grum Report post Posted May 3, 2005 ad if you really use i on both the left and the right hand side of the assignment in this construct, you should no longer be allowed to touch a computer. Or look at it, for that matter. Here's another pretty one, i personlly kinda like it if(mouse_x < win->pos_x+win->len_x-20 && mouse_x > win->pos_x+win->len_x && mouse_y > win->pos_y && mouse_y < win->pos_y+20) Share this post Link to post Share on other sites
Malaclypse Report post Posted May 3, 2005 Dir[dc].Names[Dir[dc].nf][i]=temp[i++]; For the possibility to use such constructs without forcing the compiler to suicide I really love C Share this post Link to post Share on other sites
Bongo Report post Posted May 3, 2005 Dir[dc].Names[Dir[dc].nf]=temp[i++]; That was sadez. if(mouse_x < win->pos_x+win->len_x-20 && mouse_x > win->pos_x+win->len_x && mouse_y > win->pos_y && mouse_y < win->pos_y+20) That was committed by sadez, but written by crusadingknight. Share this post Link to post Share on other sites
crusadingknight Report post Posted May 4, 2005 ad if you really use i on both the left and the right hand side of the assignment in this construct, you should no longer be allowed to touch a computer. Or look at it, for that matter. Well, there goes everyone who wrote the string manipulations library . Here's another pretty one, i personlly kinda like it if(mouse_x < win->pos_x+win->len_x-20 && mouse_x > win->pos_x+win->len_x && mouse_y > win->pos_y && mouse_y < win->pos_y+20) 158819[/snapback] Yeah, I'll own up to that one, but it does it's job, since SOMEONE still has yet to merge in a newer version of elwindows to the map editor. Share this post Link to post Share on other sites
Grum Report post Posted May 4, 2005 Oh, I have no problem with the code (though I am cleaning it up a bit), it's the logic that's at fault here. mouse_x < win->pos_x+win->len_x-20 but at the same time mouse_x > win->pos_x+win->len_x Anyway, not pointing fingers here, I make too many mistakes for that myself Share this post Link to post Share on other sites
Learner Report post Posted May 4, 2005 It is so easy to get those < and > backwards it is ridiculus! You should have seen some of the interesting bugs I had when I first revamped the Windows so it was really a system instead of lots of repeated code. Share this post Link to post Share on other sites
Grum Report post Posted May 4, 2005 I agree, we should got to a system like IF(MOUSEX.LT.WPOSX+WLENX-20.AND.MOUSEX.GT.WPOSX+WLENX)THEN and we'll never make this mistake again Share this post Link to post Share on other sites
Lachesis Report post Posted May 4, 2005 if and (<) mouse_x (-) (+) (->) win pos_x (->) win len_x 20 (>) mouse_x (+) (->) win pos_x (->) win len_x :twisted: * *) We need more emoticons Share this post Link to post Share on other sites
Placid Report post Posted May 4, 2005 The all time VB classic: if NOT ISNULL(myVar) then MsgBox "VB Sucks" endif Sorry... Share this post Link to post Share on other sites
Grum Report post Posted May 4, 2005 if and (<) mouse_x (-) (+) (->) win pos_x (->) win len_x 20 (>) mouse_x (+) (->) win pos_x (->) win len_x :twisted: * *) We need more emoticons 159030[/snapback] Lol. Took me a while to decipher because the (->) set me on the wrong track, but cute. very cute. Share this post Link to post Share on other sites
Cirion Report post Posted May 4, 2005 Dir[dc].Names[Dir[dc].nf][i]=temp[i++]; This is undefined behaviour and a bad thing. Undefined behaviour means the compiler is free to make anything it wants including setting fire to your house , so this should be avoided. Share this post Link to post Share on other sites
crusadingknight Report post Posted May 4, 2005 Oh, I have no problem with the code (though I am cleaning it up a bit), it's the logic that's at fault here. mouse_x < win->pos_x+win->len_x-20 but at the same time mouse_x > win->pos_x+win->len_x Anyway, not pointing fingers here, I make too many mistakes for that myself 158879[/snapback] That essentially means "If we've not clicked on the little x" Share this post Link to post Share on other sites
Grum Report post Posted May 4, 2005 No, it essentially means "nevah!" Share this post Link to post Share on other sites
Lachesis Report post Posted May 4, 2005 (edited) Then I guess it should be if(mouse_x < win->pos_x+win->len_x-20 /* && mouse_x > win->pos_x+win->len_x   && mouse_y > win->pos_y && */|| mouse_y > win->pos_y+20) P.S. Grum was faster than me Edited May 4, 2005 by Lachesis Share this post Link to post Share on other sites
Grum Report post Posted May 4, 2005 (edited) Lol...too much discussion for a piece of code which a) always returns false if corrected, never occurs because clicking on the close button is caught earlier EDIT: is not correct, it will still evaluate this piece of code. Edited May 4, 2005 by Grum Share this post Link to post Share on other sites
Lachesis Report post Posted May 4, 2005 Then just remove the if frame. Anyway, this thread turned out to be quite fun, and fun's never superfluous in my opinion. Share this post Link to post Share on other sites
trollson Report post Posted May 5, 2005 (edited) Just to get back to the original code snippet: Dir[dc].Names[Dir[dc].nf][i]=temp[i++]; Simplified: f[i] = g[i++]; This is a classic example of undefined behaviour. While the expression 'i++' evaluates to the prior value of 'i', the incrementation of 'i' can occur anywhere between the previous and next sequence points. Therefore, the value of 'i' used on the rhs is undefined. It may produce the desired behaviour under certain sets of conditions (compiler, version, optimisations), but there is no guarentee that it will always do so. Reference: ISO C standard, sections 6.5 (P2), 6.5.2.4 (P2). Reference: Reasonable article on sequence points. Update (observation): My installation of EL (gentoo linux) suffers from the 'missing letters' problem in a lot of the text (not all text windows, just the major ones inc. chat). The symptoms of this are any character in the first column of the font bitmap is rendered as a blank space, and some other characters have slight errors (pixels missing). According to disussion on these forums, a work around is to compile without optimisation. This behaviour is exactly as one would expect from code containing undefined behaviour like this... Particularly since this lookes like an obtuse integer error. Currently I just run a console with 'tail -f .elc/chat.txt' to get around the chat side... Edited May 9, 2005 by trollson Share this post Link to post Share on other sites