Thread: Reverse A String

  1. #16
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Great

  2. #17
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Thanks, I needed a chuckle.

    I think we all do, is it just me or is the level of nit-picking (in general) get a tad silly? I don't know maybe it's just me.


  3. #18
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by treenef
    I think we all do, is it just me or is the level of nit-picking (in general) get a tad silly? I don't know maybe it's just me.
    The functions posted are C++, using references. So first off its on the wrong board.

    The functions themselves contain undefined behavior, one being a classic example for use with describing sequence points. The second one is the version of what not to do.

    And it might be presumed that they are 'better' because it's still the 1970s and memory is expensive, CPUs lack registers. Or it's just funny bacause it is likely done "for speed" and it likely generates more code.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > there may some error above.
    There's some error below as well. Your division by 2 is a good idea if you're attempting an in-place reverse, but you're not, you're just copying half the string to the result.

    > z=i/2; //or z=i>>1;
    Special bonus points for whoever can spot why these two statements are NOT equivalent.

    > is it just me or is the level of nit-picking (in general) get a tad silly?
    The number of bogus and ill-conceived answers is certainly increasing.
    Nit pick today, or post your code with segfaults tomorrow - your choice.

  5. #20
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Quote Originally Posted by Salem
    > z=i/2; //or z=i>>1;
    Special bonus points for whoever can spot why these two statements are NOT equivalent.
    The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 / 2^E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined.
    Where are my special bonus points?

  6. #21
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    The functions themselves contain undefined behavior, one being a classic example for use with describing sequence points. The second one is the version of what not to do.

    And it might be presumed that they are 'better' because it's still the 1970s and memory is expensive, CPUs lack registers. Or it's just funny bacause it is likely done "for speed" and it likely generates more code.
    Wait... you did see my whited out text, now didn't you? Cos that was meant to be a joke.

  7. #22
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by treenef
    Wait... you did see my whited out text, now didn't you? Cos that was meant to be a joke.
    No, I didn't. Sorry.

    Unfortunately someone else might not have seen it either. There are too many bad examples out there. I'd prefer it if they all had large bold garish banners surrounding them blinking DO NOT DO THIS.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM