Common errors

This is a discussion on Common errors within the C Programming forums, part of the General Programming Boards category; Post your common errors on programming. Like the things you do wrong over and over again and spent hours and ...

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853

    Common errors

    Post your common errors on programming. Like the things you do wrong over and over again and spent hours and hours to find what is damn wrong with your program. Things that the compiler cannot catch.

    After a few seconds of thinking I ll give credit for the most frustrating error to the X,Y confusion.
    Like you want to do:
    Code:
    if (myStruct.x > endOfboardX || myStruct.x < startOfboardX)
       doThis();
    els if ((myStruct.y > endOfboardY || myStruct.x < startOfboardY)
       doThat();
    where obviously you copy paste the "y line". And I spent hours and hours trying to find out what is wrong. Grrrr damn the x,y coordination system

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    One thing that happens to me a lot (in C++) is trying to use a temporary object returned from a function and passing data in it to another function. Something like this:
    Code:
    std::string func1();
    void func2( const char* str );
    
    int main()
    {
    ...
        func2( func1().c_str() );
    ...
    }
    Then I spend lots of time trying to figure out why the string is all garbage...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Here is a list of some common ones I know people make that I can think of off hand:

    Examples:
    Code:
    /*
     * Troublesome conditions
     */
    if (i = 0)
    {
      // whatever
    }
    
    /*
     *  Sneaky semicolons
     */
    for(i = 0; i < size; ++i);
    {
      // Look, I think I am looping, but I am not.
    }
    
    /*
     * Forgetting to initialize
     */
    int x;
    
    printf("&#37;d", x);
    
    /*
     * scanf() seems to be oh so misused.
     */
    int x;
    
    scanf("%d", x);
    
    /*
     * String literals should always be constant
     */
    char *s = "Hello world!";
    
    [color=green]/*
     * Integer math woes
     */
    int x = 35;
    double y = x*2/3; // this doesn't produce what you are wanting.
    There are more, but its a good starter list.

  4. #4
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    this was painful

    Code:
    #define MAXSIZE 20;

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Code:
    /* This error is often fun to deal with since unlike my previous ones, modern compilers may not
     * always be able to cope with this.
     *
    int function(int x)
    {
      return x * x;
    }

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Unfinished comment? Wouldn't that be quite visible in the IDE?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by master5001 View Post
    Here is a list of some common ones I know people make that I can think of off hand:
    ...
    But a lot of those errors should be reported by the compiler, unless you have a low warning level set.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    Registered User
    Join Date
    Sep 2008
    Location
    California
    Posts
    19
    While writing a constructor for a node - type object in a binary search tree I accidentally assigned the indices of the top and bottom wrong, that is, I pointed the top variable to the bottom and the bottom variable to the top. That took me about 8 hours of debugging to figure out, though to be fair I did find other bugs in the process. I hate it when you make a really simple mistake and you expect it to be a higher - level error, like in how your algorithm is set up; I spent a ton of time combing my tree constructor method.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by cpjust View Post
    But a lot of those errors should be reported by the compiler, unless you have a low warning level set.
    Indeed a lot should be, however sometimes they aren't and those are the ones that destroy my sanity. Particularly when for some reason or another the IDE is not correctly pointing out the flawed area of code. Syntax highlighting is helpful but it is not always the miracle worker that you would think.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Lowest Common Factor
    By PJYelton in forum C++ Programming
    Replies: 9
    Last Post: 12-23-2002, 09:30 AM
  3. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM
  4. Most common errors
    By Barjor in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-31-2001, 05:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21