Thread: how to solve this bug??

  1. #16
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I do some part time teaching. I assure you I am not perfect. Nor are you. So given these details it not already reasonable enough to assume that your teacher is capable of making mistakes?

    lol! I just had a hilarious idea that is kind of inspired by King Mir.

    Dysfunctionally correct...
    Code:
    #include <stdio.h>
    #define void int
    int a(int n,int count){
          int i;
          for(i=0;i<n;i++)
               count =a(i,count);
               return count+1;
    }
    
    int b(int n,int count) {
      int i;
      count =a(n,count);
         for(i=0;i<n;i++)
         count =b(i,count);
         return count;
      }
    
      void main (){
        int i;
        for (i=0;i<4;i++)
          printf("&#37;d",a(i,0));
          printf("\n%d\n",a(i,10));
    
          for (i=0;i<4;i++)
            printf("%d",b(i,0));
            printf("\n%d\n",b(i,10));
    
      }
    Now everyone gets to be right

  2. #17
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Let's not give transgalactic2 a hard time.

    It is possible the original code was not a "bug" - if it compiled perfectly under a different, less picky compiler which isn't completely current-C-standard compliant.

    Hence, it's only a bug if your C implementation says it's a bug. That's the one you have to respect.

    It may not be fair, ethical, or legal, but whaddayagonnado?

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I just wanted him to be fully aware that its not an issue of being a bug. Its an issue of being illegal. Besides, problem solved with my last post. Even an angry anti-social compiler can do what you need using that code. I just wouldn't make a habit of getting rid of void all the time...

  4. #19
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I remember what it was like when the prof would give a problem and it had an obvious contradiction or bug in it. Sometimes even they get things out of some curriculum book and can't be entirely blamed. But to contradict the prof in order to get the assignment done, well, I got my fill of being labelled a "difficult student". LOL.

  5. #20
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    For me, I would rather write diabilically genius code to circumvent short-comings of the original code.

  6. #21
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i use code blocks 8.02 compiler

    do you think i need to get another compiler?

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by master5001
    I just wanted him to be fully aware that its not an issue of being a bug. Its an issue of being illegal.
    Actually, I am convinced that even in C99, void is permitted as a return type for the main function on a hosted environment, though this is a defect in the C standard. See void main() is not legal in C++ but is legal in C.

    Quote Originally Posted by transgalactic2
    i use code blocks 8.02 compiler

    do you think i need to get another compiler?
    Code Blocks is not a compiler, but an IDE. You can change your code to use int main() and return 0 when developing your code, and then just switch to void main() when you want to submit your code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Hence, it's only a bug if your C implementation says it's a bug. That's the one you have to respect.
    This is a complete load of tosh!

    char *buff;
    gets( buff );
    Now if this just happens to work on crapware 1.0, does that make it a bug-free program?

    If it does work, and you know no better, would you continue to use the same style in the belief that it was in fact the correct thing to do, just because the compiler didn't complain, and the code seemed to work?

    Or do you rely on knowledge of how C is defined to decide that it is in fact a horrible bug, without having to rely on a compiler to tell you that much.

    The big problem with the "works for me" attitude is that when, years later, you change compiler from crapware 1.0 to smartware 10.0, and it starts complaining about all sorts of things. Even when it doesn't complain, the resulting code just crashes.

    Who ya gonna blame?
    - the new compiler for telling you the truth
    - the old compiler for being a PoS
    - your old teacher for selling you snake oil
    - yourself for not listening to more experienced people when you had the chance to.

    If you just rely on a single compiler to tell you whether there is a bug, then you're doomed to relearn C every time you change compilers.

    @OP
    You could always print off N869 and add it as an appendix to your homework submission, and cite it as a reference for your answers
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Salem
    @OP
    You could always print off N869 and add it as an appendix to your homework submission, and cite it as a reference for your answers
    However, as Jonathan Pollard pointed out in the article I linked to, even in the final version of the C99 standard the defect that allows an implementation to provide void main() on a hosted environment remains, so printing N869 is of no use if the instructor points out that his or her compiler permits it. At best, one can argue that this is not portable, since implementations are not required to permit it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #25
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by Salem View Post
    > Hence, it's only a bug if your C implementation says it's a bug. That's the one you have to respect.
    This is a complete load of tosh!
    That's not what I was saying. You are talking the difference between a syntactical error and semantical (if the English analogy applies), i.e. what happens during run-time.

    If a student uses whatever compiler for his homework assignment, and it complains about some SYNTAX error, he needs to do whatever to fix the issues. That what he has to respect at-that-time. To get the thing compiling. Wouldn't you agree? The professor's code wouldn't even compile as-is. Under the local compiler. My comment makes no greater implications.

    When the program compiles fine but still has latent memory access issues (uninitialized variables, pointers, accessing past arrays, etc.) these things may or may not be catchable with modern compilers which do a lot more logic flow analyses.

    I never said that if a particular compiler passes your code alright, that it's bug free.

    A implies B does not mean B implies A.

  11. #26
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So is void main syntax or semantic, if your rubbish compiler accepts it?

    If the OP wants to carry on learning crap from a prof who doesn't know C, then that's their problem. But at least it might now be an informed decision, rather than blindly assuming that everything the prof says is golden.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #27
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i talked to my teacher and he is 100&#37; percent sure that this code works

    and he doesnt know what i am talking about

    i dont know why he thinks its ok
    because abviosly main has to be int with return 0; in the end
    Last edited by transgalactic2; 10-07-2008 at 02:55 PM.

  13. #28
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i want to understand on want basis he writes that main function in that way

    there is no way he made a typing mistake

    here is the original code scanned from his exam:

    http://img216.imageshack.us/my.php?i...5165572gm4.gif

  14. #29
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    after reading this document:
    http://homepages.tesco.net/J.deBoyne...void-main.html

    i understood that void main() is perfectly ok in C

    and that my bug happened because i use C++ compiler

    C++ allows anly int main()

  15. #30
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    The only compiler I know that "allows" void main is the Mingw compiler that comes with DevC++ ( old anyway ).

    It allows it only if you compile the code with a .c extension and not a .cpp. But even then gives a warning suggesting it should be int main().

    transgalactic2 I would seriously consider listening to everyone on this issue. Your proffessor is NOT correct in saying its ok to use void main(). This is 2008, you go out into the industry and use it in a commrical company on test console code you will get shot.

    Its better to learn right then learn backwards.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gaks bug?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-31-2008, 02:47 PM
  2. Debugging a rare / unreproducible bug..
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-05-2008, 12:56 PM
  3. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  4. Annoying bug I can't find or fix!
    By homeyg in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2004, 12:13 AM
  5. Recource Script Bug in VC++
    By Xzyx987X in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2004, 09:19 PM