What? No error?

  • Your task is simple. Write a program that should obviously produce an error on first glance either when compiled or run, but either doesn't or produces some other unrelated error. This is a popularity contest, so be creative.


    hmmmm.... this one is a brain teaser. +1

    Wish I could find it... there was an old PL/I example which included a statement along the lines of "if if if = then then then = else else else = if then else ..." (PL/I allowed using its keywords as variable names, and had a conditional expression similar to C's ?: that also used the if/then/else keywords...)

    I suggest the entire brainfuck language, because BF code just *looks* like it won't compile.

    @NigelNquande only if you're not familiar with it... ;)

  • celtschk

    celtschk Correct answer

    7 years ago

    C++



    Make sure you compile the following code in standard conforming mode (for example, for g++ use the -ansi flag):



    int main()
    {
    // why doesn't the following line give a type mismatch error??/
    return "success!";
    }


    How it works:




    The ??/ is a trigraph sequence that is translated into a backslash which escapes the following newline, so the next line is still part of the comment and therefore won't generate a syntax error. Note that in C++, omitting the return in main is well defined and equivalent to returning 0, indicating a successful run.



    I feel like the first answer just insta-won this right off the bat.

    there are warnings with -Wall

    @BЈовић Wall always throw warning about everything

    @Kiwy It throws warning only for garbage code like above. The -Wall doesn't throw warnings for everything.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM