ITT: bug-free code

int main() {return 0;}

Beware Cat Shirt $21.68

Rise, Grind, Banana Find Shirt $21.68

Beware Cat Shirt $21.68

  1. 2 weeks ago
    Anonymous

    How do you know the compiler is going to compile this correctly?

    • 2 weeks ago
      Anonymous

      Not my problem.

      • 2 weeks ago
        Anonymous

        True mindset of a programmer right there

      • 2 weeks ago
        Anonymous

        >I'm always correct and the computer is always wrong
        Based moron

        • 2 weeks ago
          Anonymous

          You misunderstand, I mean to say that would be an implementation error on behalf of the faulty compiler.

  2. 2 weeks ago
    Anonymous

    the signature of main must be either:
    int main(void);
    int main(int argc, char * argv[]);
    int main(int argc, char * * argv);

    or as a Unix extension:
    int main(int argc, char * * argv, char * * envp);

    what you posted is undefined behaviour, may as well crash.

    • 2 weeks ago
      Anonymous

      Well frick me, you're probably right...
      int main(void) {return 0;}

      OK, fixed.

      • 2 weeks ago
        Anonymous

        looks good but needs more bells and whistles

        • 2 weeks ago
          Anonymous

          No, those features cost bugs.

    • 2 weeks ago
      Anonymous

      >what you posted is undefined behaviour
      Not at all. Learn C. Even the return 0 is unnecessary.

      • 2 weeks ago
        Anonymous

        >Not at all.
        He is right about the main thing.
        int main()

        In C implies main accepts an undefined number of arguments, NOT that the function takes no arguments. In C++ however it is equivalent to
        int main(void)

        Though in practice the C initialization functions(the main isn't actually the entrypoint of the program, a bit of code from the standard library is always present to deal with argument passing and setting the environment so your C code can do its job) will automatically call your main as exit(main(argc,argv));
        >Even the return 0 is unnecessary.
        That is true since C99

        • 2 weeks ago
          Anonymous

          Fixed in C23

  3. 2 weeks ago
    Anonymous

    https://github.com/dylanaraps/hello-world.rs

  4. 2 weeks ago
    Anonymous

    #include <setjmp.h>
    #include <stdio.h>

    #define _defer_symb_comb(a, b) a ## b
    #define _defer_symb(a, b) _defer_symb_comb(a, b)

    static jmp_buf _defer_return_loc = {0};
    static jmp_buf _deferrals[1] = {0};
    static volatile unsigned char _num_deferrals = 0;

    #define DEFER_MAX 8
    #define deferral
    volatile unsigned char _num_deferrals = 0;
    jmp_buf _defer_return_loc = {0}, _deferrals[DEFER_MAX] = {0}

    #define defer
    for(int _defer_symb(_defer_n_, __LINE__) = 0;
    _defer_symb(_defer_n_, __LINE__) < 3;
    _defer_symb(_defer_n_, __LINE__)++)
    if(!_defer_symb(_defer_n_, __LINE__)) {
    printf("n_%d set 0n", __LINE__);
    if(!setjmp(_deferrals[_num_deferrals++])) {
    printf("n_%d %d aftern", __LINE__, 1);
    break;
    }
    }
    else if(_defer_symb(_defer_n_, __LINE__) == 2) {
    printf("n_%d endn", __LINE__);
    _defer_symb(_defer_n_, __LINE__) = 3;
    if(_num_deferrals) {
    longjmp(_deferrals[--_num_deferrals], 1);
    } else {
    longjmp(_defer_return_loc, 1);
    }
    }
    else

    #define return
    if(!setjmp(_defer_return_loc)) {
    if(_num_deferrals) longjmp(_deferrals[--_num_deferrals], 1);
    goto _defer_symb(_return_goto, __LINE__);
    } else _defer_symb(_return_goto, __LINE__): return

    int fn()
    {
    deferral;
    void *p = malloc(4);
    defer {
    printf("secondn");
    free(p);
    }
    defer {
    printf("firstn");
    }
    return 1;
    }

    int main()
    {
    printf("startn");
    int x = fn();
    printf("end x = %dn", x);
    return 0;
    }

    • 2 weeks ago
      Anonymous

      Nice benis

      • 2 weeks ago
        Anonymous
  5. 2 weeks ago
    Anonymous

    int main()
    {
    main("put this in your pipe and smoke it");
    return 0;
    }

    • 2 weeks ago
      Anonymous

      yessir!

  6. 2 weeks ago
    Anonymous

    // Your First C++ Program

    #include <iostream>

    int main() {
    std::cout << "Hello World!";
    return 0;
    }

  7. 2 weeks ago
    Anonymous

    The Windows NT kernel

  8. 2 weeks ago
    Anonymous

    main isn't the real entry point of c programs. Before main is run, thread local stuff is setup and atexit handler for stdout flushing. On windows it also parses argv which on windows is just one string that it has to parse into an array (with escaping) so that the arguments can be passed to main. I dunno if msvc removes this parsing code if main doesn't take argv.

Your email address will not be published. Required fields are marked *