how to solve this bug??

This is a discussion on how to solve this bug?? within the C Programming forums, part of the General Programming Boards category; I do some part time teaching. I assure you I am not perfect. Nor are you. So given these details ...

  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,831
    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,831
    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
    20,968
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,831
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,475
    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.
    I'm just trying to be a better person - My Name Is Earl

Page 2 of 3 FirstFirst 123 LastLast
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-20-2004, 11:13 PM
  5. Recource Script Bug in VC++
    By Xzyx987X in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2004, 09:19 PM

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