• (nodebb)

    Wow, the memory management is actually the first red flag I noticed.

    In C/C++ you either have a factory or you have a buffer. You don't mix them for various architectural reasons but also because you can end up with two different memory management implementations for example in the main app and libraries which would result in super weird memory issues that are super annoying to detect - often worse than multi threading issues.

  • Anonymous (unregistered)

    Actually, it isn't accessing "out of bounds" because the declaration says there are 1000 elements, and since there is an initializer, the remaining elements do get initialized to 0.

  • (nodebb)

    Wow! This is the first time ever I see a piece of code and the first adjective that comes to my mind is "cursed". Just in case, don't read it out loud because it gives the impression it might summon something nasty. :D

  • (nodebb)

    And, given that the result is an out-of-bounds array access

    Um.

    char an[1000][3] =

    No, it's not out-of-bounds. The extra 10 entries are all full of zeroes, specifically { '\0', '\0', '\0' } in each one, seeing as how the array is declared at 1000 entries.

  • Scragar (unregistered)

    we start dividing my 1000

    Should be

    we start dividing by 1000

  • (nodebb)

    I think I figured out the naming. dl is data_len, but it's used as the index into an, so I think it's the length of something that's being converted to a string, probably for display to a user. Then len_len is part of a structure called cfg, so it's probably some kind of configuration setting that means "the display length of the length property of the data".

    Or something.

  • Richard Brantley (unregistered)

    "And frankly, why we couldn't just use itoa or a similar library function which already does this and is probably more optimized than anything I'm going to write."

    I have long since concluded that a simple sense of humility can be a programmer's greatest strength.

  • (nodebb)

    That break on the 14th line won't do anything, unless this code is inside a loop that we don't see. Assuming it's not, then execution will proceed merrily along.

  • (nodebb)

    ha ha ha ha nice try, Remy, but I've been through enough that you couldn't pay me to examine that code. Those days are GONE.

    I like a good CodeSOD as much as the next reader, but I have my limits.

  • Tinkle (unregistered)

    The icing on the cake is putting the string terminator in the wrong place.

  • (nodebb) in reply to RogerC

    Even if it's in a loop it won't do anything. It's for breaking out of the switch.

    Why we have a switch statement with only one case is the new question, unless Remy chose not to show the rest of it.

  • (nodebb)

    It seems that all of you assume the memory gets zero-filled. I don't think this is guaranteed.

  • (nodebb) in reply to davethepirate

    It seems that all of you assume the memory gets zero-filled. I don't think this is guaranteed.

    It's C, which guarantees that initialised-but-not-fully aggregates (arrays, structs) are "zero"-filled in the parts that aren't initialised.

    "zero" in quotes because it's not necessarily just a memset-to-zero, if the in-memory representation of e.g. floats, doubles or NULL pointers is not the all-zeroes bit pattern. (The main culprit these days would be IBM's iSystem machines, formerly AS/400, where the bitpattern for NULL is not all-zeroes.)

  • Duke of New York (unregistered)

    I had a hunch, and yes indeed: the range 990-999 is unassigned in the north American area code plan and reserved for future expansion.

  • Brian (unregistered)

    I love how the variable is named 'll', which looks a lot like 11, which makes the condition chain really weird at first glance. If 11 < 2, else if 11 < 3, etc...

    Variable naming is an art, and this one's about on the level of a kindergartner's finger-painting.

  • Duke of New York (unregistered) in reply to davethepirate

    C89 says, in relevant part: If an object that has static storage duration is not initialized explicitly, it is initialized implicitly as if every member that has arithmetic type were assigned 0.

    What really hurts my eyes in that code is the inconsistent spacing around "operators." Working in a company that automates uniform code formatting has spoiled me.

  • (nodebb)

    We have the right to know the name of this company.

  • (author)

    itoa was one of the very first bits of code I ever got paid to write. I was a lot better-looking then.

  • (nodebb)

    @RIchard Brantley ref

    I have long since concluded that a simple sense of humility can be a programmer's greatest strength.

    Actually, IMO the greatest strength is knowing what's already built into your language / dev environment / framework / libraries, etc.

    Far more wheels are reinvented from ignorance than from hubris.

Leave a comment on “itouhhh…”

Log In or post as a guest

Replying to comment #680147:

« Return to Article