Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. You learn something new every day

You learn something new every day

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++debugginghelp
18 Posts 10 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Gary R Wheeler

    (Cue Alec Guiness) I've been writing C and C++ for a long time... a long time. I thought the preprocessor was my bitch. I had some code that compiles only for debug that I wanted removed temporarily, so I did this:

    #if defined(_DEBUG) && false
    // ... stuff to be removed
    #endif

    Not only does the VS2008 (don't ask) compiler not like that [1>.\Document.cpp(1216) : fatal error C1017: invalid integer constant expression], it's actually right! The #if expression is integral, not a boolean. You have to do this:

    #if defined(_DEBUG) && FALSE
    // ... stuff to be removed
    #endif

    (in the Windows world anyway), or this

    #if defined(_DEBUG) && 0
    // ... stuff to be removed
    #endif

    to get the effect I wanted.

    Software Zen: delete this;

    M Offline
    M Offline
    maze3
    wrote on last edited by
    #7

    Im still stuck on the truth compare. #if defined(_DEBUG) && FALSE Maybe a C/C++ thing, but wouldn't asserting to a value instead of truth logic be more readable? defined(_DEBUG) != TRUE unless this still has the integer/bool issue that you where trying to deal with?

    G 1 Reply Last reply
    0
    • M maze3

      Im still stuck on the truth compare. #if defined(_DEBUG) && FALSE Maybe a C/C++ thing, but wouldn't asserting to a value instead of truth logic be more readable? defined(_DEBUG) != TRUE unless this still has the integer/bool issue that you where trying to deal with?

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #8

      I was trying to disable the block surrounding by #if defined(_DEBUG) ... #endif temporarily, while compiling for debug. Therefore the && FALSE, which disabled it leaving the _DEBUG block in place.

      Software Zen: delete this;

      1 Reply Last reply
      0
      • G Gary R Wheeler

        raddevus wrote:

        false (bool) and FALSE (0) are two different things

        Yes indeed, a notion I noticed a month or two back in this very forum.

        Software Zen: delete this;

        O Offline
        O Offline
        obermd
        wrote on last edited by
        #9

        As far as I'm concerned, case sensitive languages are a design flaw. This flaw can't happen in case insensitive languages.

        G 1 Reply Last reply
        0
        • O obermd

          As far as I'm concerned, case sensitive languages are a design flaw. This flaw can't happen in case insensitive languages.

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #10

          Hmm. You have an interesting point of view. In the end, I think programmers like what they're used to. In my case, I've been programming in C or C-derived languages since the mid 1980's, so I expect case-sensitivity as a matter of course. I was shocked when I read that Ada was case-insensitive, as I spent three years writing Ada at one point and didn't remember that (it was a loooong time ago). Well, at least you're not one of those heathen scum who still advocate using K&R braces in preference to the vastly superior and esthetically perfect Allman brace style[^] ... :-D

          Software Zen: delete this;

          C 1 Reply Last reply
          0
          • G Gary R Wheeler

            Hmm. You have an interesting point of view. In the end, I think programmers like what they're used to. In my case, I've been programming in C or C-derived languages since the mid 1980's, so I expect case-sensitivity as a matter of course. I was shocked when I read that Ada was case-insensitive, as I spent three years writing Ada at one point and didn't remember that (it was a loooong time ago). Well, at least you're not one of those heathen scum who still advocate using K&R braces in preference to the vastly superior and esthetically perfect Allman brace style[^] ... :-D

            Software Zen: delete this;

            C Offline
            C Offline
            CodeWraith
            wrote on last edited by
            #11

            You guys have problems. [Label] Opcode [Operands] [Comment] That's all th syntax you will ever need.

            I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

            G R 2 Replies Last reply
            0
            • C CodeWraith

              You guys have problems. [Label] Opcode [Operands] [Comment] That's all th syntax you will ever need.

              I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

              G Offline
              G Offline
              Gary R Wheeler
              wrote on last edited by
              #12

              The last time I wrote a significant amount of assembly language was the late 90's. It was an OS/2 device driver for a piece of custom hardware. 18,000+ lines of assembler in the driver, relatively little of which was 'cruft' required to connect the driver to OS/2. We had a lot of functionality in that driver in order to avoid the latency of passing information out to our primary application and then back into the driver for reaction. To date in my career I think that's the smallest body of code that I've spent that much time (three years or so) concentrating on.

              Software Zen: delete this;

              C 1 Reply Last reply
              0
              • G Gary R Wheeler

                The last time I wrote a significant amount of assembly language was the late 90's. It was an OS/2 device driver for a piece of custom hardware. 18,000+ lines of assembler in the driver, relatively little of which was 'cruft' required to connect the driver to OS/2. We had a lot of functionality in that driver in order to avoid the latency of passing information out to our primary application and then back into the driver for reaction. To date in my career I think that's the smallest body of code that I've spent that much time (three years or so) concentrating on.

                Software Zen: delete this;

                C Offline
                C Offline
                CodeWraith
                wrote on last edited by
                #13

                Gary R. Wheeler wrote:

                To date in my career I think that's the smallest body of code that I've spent that much time (three years or so) concentrating on.

                Size does not matter. :-) The real question is: Was it worth it? Sounds like you spent most of that time optimizing the hell out of that code and making it 200% reliable. That sort of code tends to become 'spaghettish' and hard to maintain. No time to waste hopping up and down the stack calling neat subroutines. Still, that's what I like to spend my time on, not where I put some braces or what syntactic sugar makes the code more beautiful or not.

                I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                G 1 Reply Last reply
                0
                • C CodeWraith

                  Gary R. Wheeler wrote:

                  To date in my career I think that's the smallest body of code that I've spent that much time (three years or so) concentrating on.

                  Size does not matter. :-) The real question is: Was it worth it? Sounds like you spent most of that time optimizing the hell out of that code and making it 200% reliable. That sort of code tends to become 'spaghettish' and hard to maintain. No time to waste hopping up and down the stack calling neat subroutines. Still, that's what I like to spend my time on, not where I put some braces or what syntactic sugar makes the code more beautiful or not.

                  I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #14

                  CodeWraith wrote:

                  Sounds like you spent most of that time optimizing the hell out of that code and making it 200% reliable

                  Not really. There were lots of bug fixes, but there were also a lot of features added. The feature additions caused almost continuous refactoring in order to manage the hardware properly without thrashing the bus or triggering glitches due to race conditions. We make commercial inkjet printers, and this hardware managed the principal signals used to know where and when to spray ink. At 1000 ft/minute (17 ft/second) of paper movement, there's not a lot of time to allow for interrupt latency and such when you're printing at 600dpi.

                  Software Zen: delete this;

                  C 1 Reply Last reply
                  0
                  • G Gary R Wheeler

                    CodeWraith wrote:

                    Sounds like you spent most of that time optimizing the hell out of that code and making it 200% reliable

                    Not really. There were lots of bug fixes, but there were also a lot of features added. The feature additions caused almost continuous refactoring in order to manage the hardware properly without thrashing the bus or triggering glitches due to race conditions. We make commercial inkjet printers, and this hardware managed the principal signals used to know where and when to spray ink. At 1000 ft/minute (17 ft/second) of paper movement, there's not a lot of time to allow for interrupt latency and such when you're printing at 600dpi.

                    Software Zen: delete this;

                    C Offline
                    C Offline
                    CodeWraith
                    wrote on last edited by
                    #15

                    Sounds like fun. I'm going to try something similar at a smaller scale. Why not generate a low res VGA signal with a PIC microcontroller as a custom graphics chip for a very old 8 bit computer?

                    I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                    1 Reply Last reply
                    0
                    • R raddevus

                      This is a good one and you wrote it up clearly too. I like to read about stuff like this. Quite interesting. The interesting thing of course is also that false (bool) and FALSE (0) are two different things. :)

                      R Offline
                      R Offline
                      railita
                      wrote on last edited by
                      #16

                      The interesting thing of course is also that false (bool) and FALSE (0) are two different things. Smile | :)

                      1 Reply Last reply
                      0
                      • C CodeWraith

                        You guys have problems. [Label] Opcode [Operands] [Comment] That's all th syntax you will ever need.

                        I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                        R Offline
                        R Offline
                        Rob Grainger
                        wrote on last edited by
                        #17

                        You're oversimplifying. Evidently you need indicator columns, fixed column layout, and more. Here's subroutine from IBM's RPG language...

                        *------------------------------------------------------------------------*
                        * Subprocedure -- calculates overtime pay. *
                        *------------------------------------------------------------------------*
                        P CalcPay B
                        D CalcPay PI 8P 2
                        D Rate 5P 2 VALUE
                        D Hours 10U 0 VALUE
                        D Bonus 5P 2 VALUE
                        D Overtime S 5P 2 INZ(0)

                        /free
                        // Determine any overtime hours to be paid.
                        if Hours > 40;
                        Overtime = (Hours - 40) * Rate * 1.5;
                        Hours = 40;
                        endif;
                        // Calculate the total pay and return it to the caller.
                        return(H) Rate * Hours + Bonus + Overtime;
                        /end-free
                        P CalcPay E

                        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                        C 1 Reply Last reply
                        0
                        • R Rob Grainger

                          You're oversimplifying. Evidently you need indicator columns, fixed column layout, and more. Here's subroutine from IBM's RPG language...

                          *------------------------------------------------------------------------*
                          * Subprocedure -- calculates overtime pay. *
                          *------------------------------------------------------------------------*
                          P CalcPay B
                          D CalcPay PI 8P 2
                          D Rate 5P 2 VALUE
                          D Hours 10U 0 VALUE
                          D Bonus 5P 2 VALUE
                          D Overtime S 5P 2 INZ(0)

                          /free
                          // Determine any overtime hours to be paid.
                          if Hours > 40;
                          Overtime = (Hours - 40) * Rate * 1.5;
                          Hours = 40;
                          endif;
                          // Calculate the total pay and return it to the caller.
                          return(H) Rate * Hours + Bonus + Overtime;
                          /end-free
                          P CalcPay E

                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                          C Offline
                          C Offline
                          CodeWraith
                          wrote on last edited by
                          #18

                          Actually it's really that simple. Assembly may not be my weapon of choice for and against everything anymore, but I still use it a lot. Even a C compiler may sometimes not be practical on very small processors with limited resources.

                          I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups