• What are you working on? V7
    2,001 replies, posted
[QUOTE=high;20034293]Really if you "need" to use goto, you should probably rethink your design. I cannot think of any situation were it would be useful.[/QUOTE] That's the wrong way to see it. There are no reasons where you *need* it, but there are certainly reasons to use it. Some of them were highlighted in this thread.
If the goto statement makes a task simpler and doesn't make the code harder to understand, then anyone who complains is a giant stubborn moron. There's always a use for a given tool, just as there's always a misuse.
Ok, thanks to CammieDee666 I looked into the XNA forms thing and... it makes things so much more organized :D [IMG]http://img40.imageshack.us/img40/1977/particlegui.png[/IMG]
How would I remove window decorations in Unix for my port? Right now i'm using Xlib and I'm looking at ICCCM but I'm unsure. ...gparent?
[QUOTE=Jawalt;20033486]There's nothing wrong with a properly used goto.[/QUOTE] [img]http://imgs.xkcd.com/comics/goto.png[/img] I've never seen the reason for goto, ever. Perhaps my interpretation of how it works is wrong, but isn't it essentially the same as a loop? Ah well, most things seem useless without experience, or a good example. [editline]09:47PM[/editline] Oh, and included obligatory XKCD comic. It always pops into my head when I hear "goto" anymore.
I wrote a little program that lets you use a joystick as a mouse. It looks like trash, I know, but I spent little time working on the UI, and the rest of the 30 minutes this took writing the actual code. [img]http://imgkk.com/i/DbHRLu.png[/img] [url=http://cloud.anyhub.net/0-JoyMouse.exe][b]Download[/b][/url] It has very little error handling, so if it crashes, don't complain [editline]04:51PM[/editline] [QUOTE=GreyIOutcast;20036362]I've never seen the reason for goto, ever.[/QUOTE] [cpp] void foobar() { if(!check_this()) goto error; if(!check_that()) goto error; do_cool_stuff(); return; error: oh_no(); } [/cpp]
[QUOTE=turby;20036393][cpp] void foobar() { if(!check_this()) goto error; if(!check_that()) goto error; do_cool_stuff(); return; error: oh_no(); } [/cpp][/QUOTE] Couldn't you just use a function for that? Either that, or creating more functions is more cumbersome on the computer than I thought/knew. I haven't looked into efficient practices too much, yet.
[QUOTE=Eleventeen;20035830]How would I remove window decorations in Unix for my port? Right now i'm using Xlib and I'm looking at ICCCM but I'm unsure. ...gparent?[/QUOTE] Look at how SFML/SDL do it. Although after playing with it myself I think you're insane not using a library.
[QUOTE=turby;20036393][cpp] void foobar() { if(!check_this()) goto error; if(!check_that()) goto error; do_cool_stuff(); return; error: oh_no(); } [/cpp][/QUOTE] [cpp] void foobar() { if(!check_this()) oh_no(); if(!check_that()) oh_no(); do_cool_stuff(); return; } [/cpp] Fixed.
[QUOTE=blankthemuffin;20036527]Look at how SFML/SDL do it. Although after playing with it myself I think you're insane not using a library.[/QUOTE] To learn.
[QUOTE=arienh4;20036560][cpp] void foobar() { if(!check_this() || !check_that()) { oh_no(); return; } do_cool_stuff(); } [/cpp] Fixed.[/QUOTE] Fixed again. I guess depending on which function needs to run first you should do them as separate ifs but you forgot the return.
[QUOTE=high;20036820]Fixed again.[/QUOTE] This example does not allow for the same kind of refactoring without having to repeat yourself: [url]http://www.facepunch.com/showpost.php?p=20019977&postcount=967[/url] [QUOTE=high;20036820]I guess depending on which function needs to run first you should do them as separate ifs but you forgot the return.[/QUOTE] Not really. a() || b(), if a returns 0, all is well and b is also ran and the result depends on the return value of b. If a returns non-zero, an error occurred and b is not ran.
[QUOTE=jA_cOp;20037057]This example does not allow for the same kind of refactoring without having to repeat yourself: [url]http://www.facepunch.com/showpost.php?p=20019977&postcount=967[/url] Not really. a() || b(), if a returns 0, all is well and b is also ran and the result depends on the return value of b. If a returns non-zero, an error occurred and b is not ran.[/QUOTE] Is it defined which will execute first with ifs? I know for arithmetic it is not a defined order.
Yes it is defined, there is a sequence point at the end of the first operand of the || operator.
I was wondering, what if you go out of a scope via goto, will the locally, stack-allocated variables be deleted? e.g. [cpp]{ int a; goto somewhere; } somewhere:[/cpp] Will 'a' be destroyed properly?
I'm pretty sure that although 'a' is scoped to that inner block it still exists in the stack frame for the whole function, so it's not deleted, just out of scope. Correct me if I'm wrong.
I'm working on a sound thing [media]http://www.youtube.com/watch?v=ASkivHvyBsk[/media]
[QUOTE=animorten;20038267]I'm working on a sound thing [/QUOTE] cool
[QUOTE=ZeekyHBomb;20037858]I was wondering, what if you go out of a scope via goto, will the locally, stack-allocated variables be deleted? e.g. [cpp]{ int a; goto somewhere; } somewhere:[/cpp] Will 'a' be destroyed properly?[/QUOTE] No clue. Write a class with a destructor that outputs something and try it, I'm interested in knowing too. The "wonders" of goto. [editline]06:33AM[/editline] [QUOTE=turby;20037901]I'm pretty sure that although 'a' is scoped to that inner block it still exists in the stack frame for the whole function, so it's not deleted, just out of scope. Correct me if I'm wrong.[/QUOTE] No, each block (stuff inside { }) exists only for that block, then destructors are called and memory is freed.
Making a level editor for my game using SFML for the GUI and Irrlicht for the viewport. The way I am doing this is by creating a Win32 window and then using [url]http://www.sfml-dev.org/tutorials/1.5/graphics-win32.php[/url] For the SFML bits, and [url]http://irrlicht.sourceforge.net/docu/example014.html[/url] For the Irrlicht viewport. Woops wrong link, changed it to the right one. I'd really like it if someone could explain exactly why this is dumb.
[cpp]#include <iostream> class A{ public: A(void){ std::cout << "construct\n"; } ~A(void){ std::cout << "destruct\n"; } }; int main(void){ { A a; } { A a; goto label; } std::cout << "unreachable\n"; label: std::cout << std::flush; return 0; }[/cpp] Both are destructed properly with MSVC++ 2010b2. I'm not sure how I could create a C-equivalent. I tried [cpp]#include <stdio.h> struct A{ int unused; }; int main(void){ struct A *p; { struct A a; a.unused = 42; p = &a; goto label; } printf("unreachable\n"); label: printf("%d\n", p->unused); return 0; }[/cpp] but of course the memory could have been freed, though the data not cleaned up. Any ideas? In the disassembly you can see the call to A::~A for the C++-version, but I'm unsure what to look for in the C-version. It doesn't seem like it to me: [code]int main(void){ 00BB1380 push ebp 00BB1381 mov ebp,esp 00BB1383 sub esp,0D8h 00BB1389 push ebx 00BB138A push esi 00BB138B push edi 00BB138C lea edi,[ebp-0D8h] 00BB1392 mov ecx,36h 00BB1397 mov eax,0CCCCCCCCh 00BB139C rep stos dword ptr es:[edi] struct A *p; { struct A a; a.unused = 42; p = &a; goto label; } 00BB139E mov dword ptr [a],2Ah 00BB13A5 lea eax,[a] 00BB13A8 mov dword ptr [p],eax 00BB13AB jmp label (0BB13C4h) printf("unreachable\n"); 00BB13AD mov esi,esp 00BB13AF push offset string "unreachable\n" (0BB5740h) 00BB13B4 call dword ptr [__imp__printf (0BB82B0h)] 00BB13BA add esp,4 00BB13BD cmp esi,esp 00BB13BF call @ILT+295(__RTC_CheckEsp) (0BB112Ch) label: printf("%d\n", p->unused); 00BB13C4 mov esi,esp 00BB13C6 mov eax,dword ptr [p] 00BB13C9 mov ecx,dword ptr [eax] 00BB13CB push ecx 00BB13CC push offset string "%d\n" (0BB573Ch) 00BB13D1 call dword ptr [__imp__printf (0BB82B0h)] 00BB13D7 add esp,8 00BB13DA cmp esi,esp 00BB13DC call @ILT+295(__RTC_CheckEsp) (0BB112Ch) return 0; 00BB13E1 xor eax,eax }[/code] [editline]2:43PM[/editline] Well a built-in type of course doesn't need to call any destructor. But I can't see where 'a' is saved to; I haven't done much assembly.
How would I go about finding how to create certain filetypes? I want to write a program in c++ to compile my audiobooks to .m4b files to allow for bookmarks and chapters. I know that structs are used to define how a file is made up, but where should I look to find information on how a file is formed? I've tried doing a few google searches but I can't find anything to do with how the file is laid out.
Yes, it's in flash so it *should* go in the what are you working on web edition, but since the build-a-tree fad has been in the usual programming forum, I'll go ahead and post my version. Built in flash with AS3 (everything apart from forms and background is simple linestyle): [img]http://www.jalsoedesign.net/experiments/tree/treecreation.png[/img] Here's a link to the flash: [url]http://www.jalsoedesign.net/experiments/tree/tree.html[/url] Comes with lots of customization :)
[QUOTE=h2ooooooo;20040150]Yes, it's in flash so it *should* go in the what are you working on web edition, but since the build-a-tree fad has been in the usual programming forum, I'll go ahead and post my version. Built in flash with AS3 (everything apart from forms and background is simple linestyle): Here's a link to the flash: [url]http://www.jalsoedesign.net/experiments/tree/tree.html[/url] Comes with lots of customization :)[/QUOTE] That's awesome! I really wanted to add controls like that to my one.
[QUOTE=BAZ;20040293]That's awesome! I really wanted to add controls like that to my one.[/QUOTE] Thanks! Your experiment was highly what inspired me to make my own (as you perhaps see on the colour of the tree and the white dots at the end of branches? :D). I was pretty happy to realize that the whole code (everything from all the buttons to the branch and root creation, etc. etc. etc.) was only 139 lines long, which was what I hoped it'd be (not too long and complicated). It's very basic (I have no idea if you did it the same way) and it simply works by first creating all the main variables in the main scope (all the options of the controls), adding events to the button and having 3 arrays that the whole system is built on. One array for following of each: arrBranches, arrRoots and arrEndDots. The program the executes the main function, generates the root (static, except the endX and endY, and then slightly random rotated), and then adds a random amount of branches that each call the same function (recursive). Every time a branch is added, it's added to the arrBranches array, and goes through a for loop where it creates branches by using the following code: arrBranches.push(new Array(intLevel, intEndX, intEndY, intCurrentRotation)); for (var i:int = 0; i < intBranchesToCreate; i++) createBranch(intBranchID); intBranchesToCreate is random, intLevel is the current level (0 is the main, 10 is the ends etc.), endX and endY is the ending x and y position of the current branch for use with the next branchs start positions, and intCurrentRotation is a matter of its rotation (instead of just a random 360 degrees, it works using a minimum and a maximum based on parent rotation). The intBranchID refers to the position in the arrBranches array, and can then be refered to when the function is called again. The roots basically work the same way, except they don't have the staticness of the main piece. After both roots and branches are added, it goes through the arrEndDots array and creates dots on every single of the end branches based on 3 parameters: level, endx and endy. I'd be interested in knowing if you took the same approach of if you did it another way? :) [editline]04:09PM[/editline] Also fixed bug with the minimum and maximum angle not working correct (it always leaned a bit to the right).
Editor so far. The irrlicht viewport is only part of the window, on the panel on the right is an SFML viewport. Buttons will go on the right to spawn stuff and move it around. It's a simple block style game so editing will be pretty easy, but I'm expecting the editor to turn out quite pleasant. [img]http://i47.tinypic.com/2n037gn.jpg[/img] Also I love how this 1024x600 window fits perfectly into my post (1280x1024 screen res)
I wrote a python script that retrieves the latest blog post from a tumblr blog and parses it so it's ready to post to a forum. Except, I don't know how I would go about getting it to post to a forum, any ideas?
-snip- I was wrong.
For those saying "GOTO has no use!", I defy you to deny you have ever typed this into a BBC Model B: [code] 10 PRINT "YOU ARE GAY" 20 GOTO 10 [/code]
[QUOTE=CarlBooth;20042624]For those saying "GOTO has no use!", I defy you to deny you have ever typed this into a BBC Model B: [code] 10 PRINT "YOU ARE GAY" 20 GOTO 10 [/code][/QUOTE] I have never used a BBC Model B, so I can deny that I have typed that :v:
Sorry, you need to Log In to post a reply to this thread.