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. General Programming
  3. C / C++ / MFC
  4. Keywords that I don't understand

Keywords that I don't understand

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionlearning
33 Posts 5 Posters 0 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.
  • J Jeremy Falcon

    Stephen Hewitt wrote:

    Macros make debugging harder and are not type safe.

    Also, if you need a debugger for a one-line routine, let's just say you're better off being a Wal-Mart cashier. Let's get real man, you know that realistically speaking a one line routine isn't that big of a deal to debug. Or dare I say, just copy and paste the contents of the macro into a block and run it if you must and then put the modified code back into the macro. The benefits outweigh having to use two extra keystrokes IMO.

    Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

    S Offline
    S Offline
    Stephen Hewitt
    wrote on last edited by
    #10

    Jeremy Falcon wrote:

    Or dare I say, just copy and paste the contents of the macro into a block and run it if you must and then put the modified code back into the macro. The benefits outweigh having to use two extra keystrokes IMO.

    Or just use inline and save yourself the hastle and enjoy type safety to boot!

    Steve

    J 1 Reply Last reply
    0
    • S Stephen Hewitt

      I was not (and am not) attempting to be pretentious. I said that your original statement about inline functions making functions bigger was “not true for really small functions.”:

      Jeremy Falcon wrote:

      Of course, if you call an inline function a lot, you'll increase the size of your exe substantially.

      Stephen Hewitt wrote:

      This is not true for really small functions. For example if a function simply added two numbers or returned some value then the function call overhead will be bigger then the actual code and inlining will save time and space.

      To this you replied as follows:

      Jeremy Falcon wrote:

      We both know the smaller the function the less the increase in executable, so my statement isn't incorrect. But the increase is still substantial relative to the routine.

      I did read your posts and have done so again when preparing this reply. Your assertion that, “if you call an inline function a lot, you'll increase the size of your exe substantially”, is simply not true for small functions. In fact the opposite is true: if the inline function is small then the more you call it the more space you’ll save! You’ve obviously interpreted my (correct) comments as a personal attack. This is not the case. The CodeProject is about sharing knowledge and such. I can see nowhere in you post to justify your assertion that you, “didn't deny your points on one-line routines.”

      Steve

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #11

      Stephen Hewitt wrote:

      I said that your original statement about inline functions making functions bigger was “not true for really small functions.”:

      You said that, and I said nothing to counter and yet you go on like I'm impressed or something.

      Stephen Hewitt wrote:

      I did read your posts and have done so again when preparing this reply. You assertion that, “if you call an inline function a lot, you'll increase the size of your exe substantially”, is simply not true for small functions. In fact the opposite is true: if the inline function is small then the more you call it the more space you’ll save!

      My point that the increase is relative to the size of the routine wasn't disproved. Yet you say it is, that's incorrect and for no other reason that I can surmise expect you're just looking to argue and/or just don't listen. And yeah obviously, I wasn't talking about one-line routines at first, as I wouldn't do that, but I never denied your point on them. Which is why I find it odd you continue to press. I did say my statement was correct still however.

      Stephen Hewitt wrote:

      You’ve obviously interpreted my (correct) comments as a personal attack.

      I think you need to look up the word pretentious.

      Stephen Hewitt wrote:

      I can see no where in you post to justify you assertion that you, “didn't deny your points on one-line routines.”

      Really, well I don't see where I DID write one-line routines are bigger.

      Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

      1 Reply Last reply
      0
      • S Stephen Hewitt

        Jeremy Falcon wrote:

        Or dare I say, just copy and paste the contents of the macro into a block and run it if you must and then put the modified code back into the macro. The benefits outweigh having to use two extra keystrokes IMO.

        Or just use inline and save yourself the hastle and enjoy type safety to boot!

        Steve

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #12

        Stephen Hewitt wrote:

        Or just use inline and save yourself the hastle and enjoy type safety to boot!

        Ok, it's not much less type safe (way to miss a point again). And, save yourself two keystrokes for something rarely debugged in the first place and give yourself way more problems in exchange - yeah great advice.

        Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

        L S 2 Replies Last reply
        0
        • J Jeremy Falcon

          Stephen Hewitt wrote:

          Or just use inline and save yourself the hastle and enjoy type safety to boot!

          Ok, it's not much less type safe (way to miss a point again). And, save yourself two keystrokes for something rarely debugged in the first place and give yourself way more problems in exchange - yeah great advice.

          Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #13

          "The first rule about . . [macros] is: don't use them if you do not have to. . . almost every macro demonstrates a flaw in either the programming language or in the program." - Stroustrup

          J 1 Reply Last reply
          0
          • L Lost User

            "The first rule about . . [macros] is: don't use them if you do not have to. . . almost every macro demonstrates a flaw in either the programming language or in the program." - Stroustrup

            J Offline
            J Offline
            Jeremy Falcon
            wrote on last edited by
            #14

            Having a truckload of simple inline functions to replace macros would demonstrate this same design flaw that he was referring to. Remember, if you understand what he was actually saying, it's not the macro itself itself that's the problem; it's the design flaw behind abusing it. Which is no better or worse than simply replacing it with an inline routine and leaving the same design.

            Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

            L 1 Reply Last reply
            0
            • J Jeremy Falcon

              Having a truckload of simple inline functions to replace macros would demonstrate this same design flaw that he was referring to. Remember, if you understand what he was actually saying, it's not the macro itself itself that's the problem; it's the design flaw behind abusing it. Which is no better or worse than simply replacing it with an inline routine and leaving the same design.

              Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #15

              Jeremy Falcon wrote:

              Having a truckload of simple inline functions to replace macros would demonstrate this same design flaw that he was referring to.

              No it would not. I sugest you grab a copy of his book and read his comments in context. Also Scott Meyers addresses the issue in one of his books. Also this[^] discussion is relevant.

              Jeremy Falcon wrote:

              if you understand what he was actually saying

              I pretty confident I have a good idea what he is getting at but if you think you know better than him or me macro away till the cows come home, I really dont care

              J 1 Reply Last reply
              0
              • L Lost User

                Jeremy Falcon wrote:

                Having a truckload of simple inline functions to replace macros would demonstrate this same design flaw that he was referring to.

                No it would not. I sugest you grab a copy of his book and read his comments in context. Also Scott Meyers addresses the issue in one of his books. Also this[^] discussion is relevant.

                Jeremy Falcon wrote:

                if you understand what he was actually saying

                I pretty confident I have a good idea what he is getting at but if you think you know better than him or me macro away till the cows come home, I really dont care

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #16

                Josh Gray wrote:

                Also this[^] discussion is relevant.

                It's also confusing bad macro design with bad design in general. Apples to oranges.

                Josh Gray wrote:

                but if you think you know better than him or me macro away till the cows come home, I really dont care

                Tell me then, since he designed C++, why didn't he drop macro support if he loathed the mere existence of them that much? Compatibility can't be the reason as it was a brand new language at the time, and wouldn't effect C. I can understand making it completely compile C code, but why not specify compilers replace macros with something else under the hood, etc. I mean, why keep them if they're so bad?

                Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                L 1 Reply Last reply
                0
                • A Alex Cutovoi

                  Hi fellows I'm programming C++ approximately 1 1/2 year, and I programming for windows too. But some keywords I don't know exactly what they are and when I use them. That's my question: What the meaning of terms and when I use them: __stdcall __pascal __fastcall __thiscall inline It seems that's beginner question but I would like some answer to this question Thanks for help again

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #17

                  inline is the standout, it's different to the others. inline is a *suggestion* to the compiler that this function is so simple, that it's more efficient to write the code for this function in the places where it's called, instead of paying the cost of a call to another memory address to run it. The vital thing to understand is that hte compiler is both free to inline things itself, and to decide you're wrong and *not* inline the function.

                  Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  J 1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    Stephen Hewitt wrote:

                    Or just use inline and save yourself the hastle and enjoy type safety to boot!

                    Ok, it's not much less type safe (way to miss a point again). And, save yourself two keystrokes for something rarely debugged in the first place and give yourself way more problems in exchange - yeah great advice.

                    Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #18

                    No, I'm not missing the point. Perhaps you can explain the advantages of macros over inline functions? There are some things inline functions can't do like stringisation and token pasting and such; but when inline functions can be used they're a better solution for many reasons including the following:  - Type safety.  - Automatically disabled in debug builds to aid debugging.  - Can use multiline constructs without having to end each line with a "\".  - Can be put into namespaces!  - Can be members of classes and structs!  - Can be overloaded!  .  .  .

                    Steve

                    J 2 Replies Last reply
                    0
                    • S Stephen Hewitt

                      No, I'm not missing the point. Perhaps you can explain the advantages of macros over inline functions? There are some things inline functions can't do like stringisation and token pasting and such; but when inline functions can be used they're a better solution for many reasons including the following:  - Type safety.  - Automatically disabled in debug builds to aid debugging.  - Can use multiline constructs without having to end each line with a "\".  - Can be put into namespaces!  - Can be members of classes and structs!  - Can be overloaded!  .  .  .

                      Steve

                      J Offline
                      J Offline
                      Jeremy Falcon
                      wrote on last edited by
                      #19

                      Stephen Hewitt wrote:

                      Perhaps you can explain the advantages of macros over inline functions?

                      Perhaps you can read my posts and find the answer there already seeing as I said it more than once.

                      Stephen Hewitt wrote:

                      - Type safety.

                      Addressed twice. The type safety you refer to isn't a real issue since a macro expands to type safe code.

                      Stephen Hewitt wrote:

                      - Automatically disabled in debug builds to aid debugging.

                      And like typing #ifdef _DEBUG will break your arm.

                      Stephen Hewitt wrote:

                      - Can use multiline constructs without having to end each line with a "\".

                      You know you're reaching deep when you have syntax as reasoning. :laugh:

                      Stephen Hewitt wrote:

                      - Can be put into namespaces! - Can be members of classes and structs. - Can be overloaded.

                      Actually these are very good points, but it doesn't really mean inline functions should always be used in place of macros as you suggest. Besides, this has contradicting logic. I mean, why write an inline function... usually for speed right? Using the second two of your three points quoted would effectively break that anyway.

                      Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                      S 1 Reply Last reply
                      0
                      • C Christian Graus

                        inline is the standout, it's different to the others. inline is a *suggestion* to the compiler that this function is so simple, that it's more efficient to write the code for this function in the places where it's called, instead of paying the cost of a call to another memory address to run it. The vital thing to understand is that hte compiler is both free to inline things itself, and to decide you're wrong and *not* inline the function.

                        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                        J Offline
                        J Offline
                        Jeremy Falcon
                        wrote on last edited by
                        #20

                        Christian Graus wrote:

                        inline is a *suggestion* to the compiler that this function is so simple

                        I hate to use your post, but that's a great reason I forgot. There is no real guarantee inline will even work. You're guaranteed to have inline expansion with macros though. Man, old age is getting to me. :-O

                        Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                        S 1 Reply Last reply
                        0
                        • S Stephen Hewitt

                          No, I'm not missing the point. Perhaps you can explain the advantages of macros over inline functions? There are some things inline functions can't do like stringisation and token pasting and such; but when inline functions can be used they're a better solution for many reasons including the following:  - Type safety.  - Automatically disabled in debug builds to aid debugging.  - Can use multiline constructs without having to end each line with a "\".  - Can be put into namespaces!  - Can be members of classes and structs!  - Can be overloaded!  .  .  .

                          Steve

                          J Offline
                          J Offline
                          Jeremy Falcon
                          wrote on last edited by
                          #21

                          Stephen Hewitt wrote:

                          - Can be members of classes and structs! - Can be overloaded!

                          Now that I think about it, that extra cost my be placed on the compile time rather than the run time. But alas, I'm too lazy and and it's getting too late for me to look into it.

                          Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                          1 Reply Last reply
                          0
                          • J Jeremy Falcon

                            Stephen Hewitt wrote:

                            Perhaps you can explain the advantages of macros over inline functions?

                            Perhaps you can read my posts and find the answer there already seeing as I said it more than once.

                            Stephen Hewitt wrote:

                            - Type safety.

                            Addressed twice. The type safety you refer to isn't a real issue since a macro expands to type safe code.

                            Stephen Hewitt wrote:

                            - Automatically disabled in debug builds to aid debugging.

                            And like typing #ifdef _DEBUG will break your arm.

                            Stephen Hewitt wrote:

                            - Can use multiline constructs without having to end each line with a "\".

                            You know you're reaching deep when you have syntax as reasoning. :laugh:

                            Stephen Hewitt wrote:

                            - Can be put into namespaces! - Can be members of classes and structs. - Can be overloaded.

                            Actually these are very good points, but it doesn't really mean inline functions should always be used in place of macros as you suggest. Besides, this has contradicting logic. I mean, why write an inline function... usually for speed right? Using the second two of your three points quoted would effectively break that anyway.

                            Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                            S Offline
                            S Offline
                            Stephen Hewitt
                            wrote on last edited by
                            #22

                            No one says macros should never be used, just that they shouldn’t be used when other superior constructs exist for the same task; the specific example in this case is that macros should not be used as inline functions. I have constantly argued the point, complete with examples and data (compiler output) to support my claims; while you seem intent on arguing the person and accusing people of missing the point. Well I've had my say and I'll let my comments speak for themselves.

                            Steve

                            J 2 Replies Last reply
                            0
                            • J Jeremy Falcon

                              Josh Gray wrote:

                              Also this[^] discussion is relevant.

                              It's also confusing bad macro design with bad design in general. Apples to oranges.

                              Josh Gray wrote:

                              but if you think you know better than him or me macro away till the cows come home, I really dont care

                              Tell me then, since he designed C++, why didn't he drop macro support if he loathed the mere existence of them that much? Compatibility can't be the reason as it was a brand new language at the time, and wouldn't effect C. I can understand making it completely compile C code, but why not specify compilers replace macros with something else under the hood, etc. I mean, why keep them if they're so bad?

                              Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #23

                              Jeremy Falcon wrote:

                              Tell me then, since he designed C++, why didn't he drop macro support if he loathed the mere existence of them that much? Compatibility can't be the reason as it was a brand new language at the time, and wouldn't effect C. I can understand making it completely compile C code, but why not specify compilers replace macros with something else under the hood, etc. I mean, why keep them if they're so bad?

                              Obviously I could only speculate at this and that would be pointless. It is my preference to avoid macros whenever possible.

                              J 1 Reply Last reply
                              0
                              • S Stephen Hewitt

                                No one says macros should never be used, just that they shouldn’t be used when other superior constructs exist for the same task; the specific example in this case is that macros should not be used as inline functions. I have constantly argued the point, complete with examples and data (compiler output) to support my claims; while you seem intent on arguing the person and accusing people of missing the point. Well I've had my say and I'll let my comments speak for themselves.

                                Steve

                                J Offline
                                J Offline
                                Jeremy Falcon
                                wrote on last edited by
                                #24

                                Stephen Hewitt wrote:

                                No one says macros should never be used, just that they shouldn’t be use when other superior constructs exist for the same task; the specific example in this case is that macros should not be used as inline functions.

                                I'm sorry you don't understand context - my bad. I'll have to remember that next time I write something.

                                Stephen Hewitt wrote:

                                I have constantly argued the point, complete with examples and data (compiler output) to support my claims;

                                And that makes you correct how?

                                Stephen Hewitt wrote:

                                while you seem intent on arguing the person and accusing people of missing the point. Well I've had my say and I'll let my comments speak for themselves.

                                Fair enough, but don't accuse me of what you did, and that is to argue a point I never spoke against. Have a nice day.

                                Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                1 Reply Last reply
                                0
                                • S Stephen Hewitt

                                  No one says macros should never be used, just that they shouldn’t be used when other superior constructs exist for the same task; the specific example in this case is that macros should not be used as inline functions. I have constantly argued the point, complete with examples and data (compiler output) to support my claims; while you seem intent on arguing the person and accusing people of missing the point. Well I've had my say and I'll let my comments speak for themselves.

                                  Steve

                                  J Offline
                                  J Offline
                                  Jeremy Falcon
                                  wrote on last edited by
                                  #25

                                  Stephen Hewitt wrote:

                                  No one says macros should never be used, just that they shouldn’t be use when other superior constructs exist for the same task; the specific example in this case is that macros should not be used as inline functions.

                                  Actually, I just reread what I said. I did mention inline functions. Perhaps you should bother reading my posts... oh wait.

                                  Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    Jeremy Falcon wrote:

                                    Tell me then, since he designed C++, why didn't he drop macro support if he loathed the mere existence of them that much? Compatibility can't be the reason as it was a brand new language at the time, and wouldn't effect C. I can understand making it completely compile C code, but why not specify compilers replace macros with something else under the hood, etc. I mean, why keep them if they're so bad?

                                    Obviously I could only speculate at this and that would be pointless. It is my preference to avoid macros whenever possible.

                                    J Offline
                                    J Offline
                                    Jeremy Falcon
                                    wrote on last edited by
                                    #26

                                    Josh Gray wrote:

                                    Obviously I could only speculate at this and that would be pointless. It is my preference to avoid macros whenever possible.

                                    Well, let's make a deal. I won't hold it against you if you don't hold it against me for sneaking the occasional macro or two in some code when you're not looking. :-D

                                    Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                    L 1 Reply Last reply
                                    0
                                    • J Jeremy Falcon

                                      Josh Gray wrote:

                                      Obviously I could only speculate at this and that would be pointless. It is my preference to avoid macros whenever possible.

                                      Well, let's make a deal. I won't hold it against you if you don't hold it against me for sneaking the occasional macro or two in some code when you're not looking. :-D

                                      Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #27

                                      Jeremy Falcon wrote:

                                      if you don't hold it against me for sneaking the occasional macro or two in some code when you're not looking.

                                      Its a long piece of rope, you do what you like with it

                                      1 Reply Last reply
                                      0
                                      • J Jeremy Falcon

                                        Christian Graus wrote:

                                        inline is a *suggestion* to the compiler that this function is so simple

                                        I hate to use your post, but that's a great reason I forgot. There is no real guarantee inline will even work. You're guaranteed to have inline expansion with macros though. Man, old age is getting to me. :-O

                                        Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                        S Offline
                                        S Offline
                                        Stephen Hewitt
                                        wrote on last edited by
                                        #28

                                        The only times I've seen MSVC ignore an inline directive is when its had no choice such as with recursive functions: in this context this is a feature.

                                        Steve

                                        J 1 Reply Last reply
                                        0
                                        • S Stephen Hewitt

                                          The only times I've seen MSVC ignore an inline directive is when its had no choice such as with recursive functions: in this context this is a feature.

                                          Steve

                                          J Offline
                                          J Offline
                                          Jeremy Falcon
                                          wrote on last edited by
                                          #29

                                          Stephen Hewitt wrote:

                                          The only times I've seen MSVC ignore an inline directive is when its had no choice such as with recursive functions: in this context this is a feature.

                                          And MSVC is the only compiler in existence too.

                                          Jeremy Falcon "It's a good thing to do and a tasty way to do it." - Wilford Brimley[^]

                                          S 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