GWatt's Profile User Rating: *****

Reputation: 278 Architect
Group:
Expert w/DIC++
Active Posts:
3,070 (0.93 per day)
Joined:
01-December 05
Profile Views:
40,742
Last Active:
User is offline Today, 07:37 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
525

Latest Visitors

Icon   GWatt has not set their status

Posts I've Made

  1. In Topic: goto

    Posted 29 Nov 2014

    Since I enjoy beating dead horses and shouting into the wind, I'll state my opinion. I think gotos can be used well. The classical and canonical example is, of course, symmetric resource cleanup in C.
      if (x = acquire1()) ;
      else goto _end;
    
      if (y = acquire2()) ;
      else goto _cleanup_x;
      /* do actual stuff */
      cleanup2(y);
    _cleanup_x:
      cleanup1(x);
    _end:
      return retval;
    
    

    There are three ways around this using goto for this particular issue:

    • nested if/else around the acquisition and release codes to handle every possible code path.
    • putting your logic inside of a do-while(0) loop, setting a status code and breaking on failure, and using a switch with case fallthrough to handle cleanup.
    • splitting all acquisition into separate functions.

    1 gets messy fast.
    2 is basically just emulating gotos/labels. The difference is a matter of taste.
    3 (to me) is the most nuanced. If you can reuse the acquisition and logic, go for it. Otherwise, you're unnecessarily splitting up the code.

    I've also found an occasional use for goto in conjunction with loops. Consider building this prime sieve:
      /* primes: list of primes
         c: current count of primes
         n: total number of primes
      */
      for (int p = 3; c < n; p++) {
        for (int i = 0; i < c || primes[i] * primes[i] <= p; i++) {
          if (p % primes[i] == 0) goto _notprime;
        }
        primes[c++] = p;
    _notprime:;
      }
    
    

    The alternative is to maintain a flag. It's definitely a matter of taste, but I prefer the goto.
  2. In Topic: Linux -- What do you look for in a distro?

    Posted 5 Oct 2014

    I feel like expanding upon my earlier answer as it was pretty terse.
    In all honesty, most of the distros I've used feel the same. This makes sense as almost all of them have the gnu tools/libraries on top of the linux kernel. The differences mainly come from the package/update manager and how the distros organize the software. You can get most any desktop environment for any distro (not sure about Unity,) so there's no reason to pick one distro over the other simply because you like its default DE better.
    I previously mentioned Fedora, which I currently have on my workstation. What I didn't say is that I have a debian system in my home acting as a dns/dhcp server, a vps that's also running debian, the servers I manage for work are running a mix of ubuntu and debian, and finally the automotive grade PCs I program are running Wind River Linux. To me, all of those systems are basically identical. In the past I've used Gentoo, Slackware, and Arch and they also feel pretty much the same. (Gentoo feels the most different because you have to compile every single piece of software, and then go back and recompile half of them because you forgot to enable jpgs in your browser. Supposedly once you get Gentoo up and running it's great, but my experience was by the time you finished upgrading packages, new ones had already come out.)
    It doesn't matter that some things are organized differently or that the software versions can be wildly different. It's all just gnu on top of a linux kernel.
    I'm confident that pretty much any linux distribution you might choose will not be meaningfully different from any other.
  3. In Topic: Linux -- What do you look for in a distro?

    Posted 5 Oct 2014

    I've been a Fedora user on and off since its initial release. What I look for most is a decent package manager, and a wide selection of packages.
    Having said that, I do like slackware quite a bit, although I don't have it installed on any machines at the moment.
    I use KDE out of convenience; I have no real attachment to its eye candy.
  4. In Topic: Possible Strcpy issue causing (lldb) pausing code

    Posted 4 Oct 2014

    Look at line 12 of your code.

    Quote

     char word[20], DonInvType[100][20], ReqInvType[0];
    
    


    ReqInvType is an array of zero characters so any attempt to use it is likely to fail. I also find it questionable that you are (1) using strcpy over strncpy, and (2) using it on two pointers that could overlap. Look at the documentation for strcpy/strncpy for more information on them.

    What is ReqInvType supposed to be used for?
  5. In Topic: John Carmack

    Posted 26 Sep 2014

    why doesntmy code wirk

    #inculed <sdtio.h

    void main (char string ){
    string="hello world"
    prinft(strgni)
    }

My Information

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
10
Programming Languages:
C, C++, Objective C, arm assembly, Java, perl, scheme, python

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

Page 1 of 1
  1. Photo

    Biggie_smallz Icon

    04 Feb 2013 - 22:57
    Hello Gwatt can you please get back to me.. I need help with some scheme programming?
  2. Photo

    raghav.naganathan Icon

    17 Oct 2012 - 01:11
    Dude...before your reputation changes, I would like to tell you that it(256) is a perfect square :)
  3. Photo

    GWatt Icon

    27 Dec 2010 - 22:52
    @arob, I haven't used Java regularly in years. Most of what I do now is in C or scheme. However, there are several tutorials on this site and on others that should get you well on your way to learning Java.
  4. Photo

    arob Icon

    25 Dec 2010 - 23:31
    hey can u help to learn java .
  5. Photo

    GWatt Icon

    24 Jun 2010 - 19:59
    Pretty sure it has 4.
  6. Photo

    no2pencil Icon

    22 Jun 2010 - 20:06
    Where you plugged the phone, does it have four prongs or just two? I've had trouble using rotary phones on digital lines, other times it works flawlessly.
  7. Photo

    GWatt Icon

    30 May 2010 - 06:35
    Yeah, that did get removed in the upgrade. Oh and my rotary phone works fine. I use it in my dorm. It was simply our house lines that it doesn't like.
  8. Photo

    no2pencil Icon

    06 May 2010 - 01:13
    It's back! YAY!
    The phone I mean...
  9. Photo

    no2pencil Icon

    02 Mar 2010 - 03:47
    Hey man! Looks like after the upgrade you are no longer sporting the Rotary Phone...
Page 1 of 1