• (disco) in reply to xaade
    xaade:
    You just have to reserve a value to represent infinity, then create the rules for how it interacts with other values.

    The C++ Standard explicitly prohibits integer types from having a representation for infinity.

  • (disco) in reply to dkf
    dkf:
    PJH:
    -ftemplate-depth=99999
    dkf:
    Nearly 3 and a half minutes to count to about 10k?

    I think you'll find that's about 100k.


    Filed under: Off by 10 error
  • (disco) in reply to Dreikin

    Flagged for pendantry.

  • (disco) in reply to Dreikin
    Dreikin:
    I think you'll find that's about 100k.

    Umm, yeah. Hanzo'd.

    Still, it's not like it ought to take very long. 3½ minutes is criminal. What are they doing, using linear searches of a linked list for template matching?

  • (disco)

    Foreach loop that runs once?

  • (disco) in reply to dkf
    dkf:
    3½ minutes is criminal. What are they doing, using linear searches of a linked list for template matching?

    They probably assume that programmers aren't doing what you're trying to do here, which is a pretty reasonable assumption. If you try to break the compiler, you get to put up with the results.

  • (disco) in reply to FrostCat
    FrostCat:
    Flagged for pendantry.

    :smiley:

  • (disco) in reply to dkf
    dkf:
    Umm, yeah. Hanzo'd.

    Still, it's not like it ought to take very long. 3½ minutes is criminal. What are they doing, using linear searches of a linked list for template matching?

    I wonder if it's something like:

    1. Copy file
    2. Add instantiation of template<i> to source
    3. Delete old file
    4. Re-evaluate new version of file
    5. Find we need template i+1
    6. Set i to i+1
    7. Goto 1.
  • (disco)

    Finally got some time to do some testing.

    #include <iostream>
    
    bool isTurtlesHere(int)
    {
        return true;
    }
    
    template<unsigned short i> // or unsigned char
    bool isTurtlesAllTheWayDown()
    {
        if (isTurtlesHere(i)) {
            return isTurtlesAllTheWayDown<i+1>();
        } else {
            return false;
        }
    }
    
    int main()
    {
        if (isTurtlesAllTheWayDown<0>()) {
            std::cout << "Copernicus was wrong";
        } else {
            std::cout << "Copernicus was right";
        }
    }
    

    The results are as expected: the code compiles without any warning (g++ -Wall -Wextra), without optimizations it segfaults, with optimizations we get infinite loop. For unsigned char, it takes a fraction of second to compile. For unsigned short, nonoptimized compilation takes 70 seconds, optimized takes 43 seconds. Binary sizes are as follows:

    -rwxr-xr-x 1   42112 11-05 18:15 char-nonoptimized.out
    -rwxr-xr-x 1    7554 11-05 18:15 char-optimized.out
    -rwxr-xr-x 1 8844424 11-05 18:13 short-nonoptimized.out
    -rwxr-xr-x 1    7554 11-05 18:14 short-optimized.out
    

    I don't know how, but I was sure I sent this post yesterday... But apparently I didn't. But it got saved in the cumulonimbus and now, on another computer, I still have a complete text I've written. Discourse having useful feature? TRWTF right here.

Leave a comment on “Brick by Brick”

Log In or post as a guest

Replying to comment #:

« Return to Article