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. A function that does... nothing... :-).

A function that does... nothing... :-).

Scheduled Pinned Locked Moved The Weird and The Wonderful
announcement
12 Posts 11 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.
  • M MarkB777

    /******************************************************************************
    FUNCTION : lpf_Null
    DESCRIPTION : Does nothing.
    ******************************************************************************/
    static void lpf_Null(void)
    {

    }

    Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

    S Offline
    S Offline
    Stanciu Vlad
    wrote on last edited by
    #2

    Is that function used inside the application or it was created just for a better and larger number of lines?

    I have no smart signature yet...

    M 1 Reply Last reply
    0
    • S Stanciu Vlad

      Is that function used inside the application or it was created just for a better and larger number of lines?

      I have no smart signature yet...

      M Offline
      M Offline
      MarkB777
      wrote on last edited by
      #3

      No its used as a handler function in a state machine. The function is really just a bi-product of the design... but still... I thought it was funny :).

      Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

      P C 2 Replies Last reply
      0
      • M MarkB777

        /******************************************************************************
        FUNCTION : lpf_Null
        DESCRIPTION : Does nothing.
        ******************************************************************************/
        static void lpf_Null(void)
        {

        }

        Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #4

        Doing nothing is considerably better then doing some of the things that show up on this board :D

        Jeroen De Dauw
        Blog ; Wiki

        C 1 Reply Last reply
        0
        • M MarkB777

          /******************************************************************************
          FUNCTION : lpf_Null
          DESCRIPTION : Does nothing.
          ******************************************************************************/
          static void lpf_Null(void)
          {

          }

          Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #5

          I've created a few of those myself - sometimes it is a much better way than providing a special case. Think delegate that doesn't need a null test, for example. At least it had a sensible name!

          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M MarkB777

            No its used as a handler function in a state machine. The function is really just a bi-product of the design... but still... I thought it was funny :).

            Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

            P Offline
            P Offline
            Peter_in_2780
            wrote on last edited by
            #6

            Agreed. State machines often need a null action when only the state transition is wanted. I've written plenty of 'em over the years, particularly in comms protocol implementations.

            Software rusts. Simon Stephenson, ca 1994.

            N 1 Reply Last reply
            0
            • J Jeroen De Dauw

              Doing nothing is considerably better then doing some of the things that show up on this board :D

              Jeroen De Dauw
              Blog ; Wiki

              C Offline
              C Offline
              Chris Boden
              wrote on last edited by
              #7

              I have to agree. The man that wrote it is clearly some sort of relative genius.

              1 Reply Last reply
              0
              • M MarkB777

                /******************************************************************************
                FUNCTION : lpf_Null
                DESCRIPTION : Does nothing.
                ******************************************************************************/
                static void lpf_Null(void)
                {

                }

                Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #8

                lpf_NoOp might be a better name.

                S 1 Reply Last reply
                0
                • P PIEBALDconsult

                  lpf_NoOp might be a better name.

                  S Offline
                  S Offline
                  supercat9
                  wrote on last edited by
                  #9

                  PIEBALDconsult wrote:

                  lpf_NoOp might be a better name.

                  From a logical perspective, I think the meaning and intention of "ptr = lpf_Null;" may be a little clearer than lpf_NoOp;" especially if there are places where the pointer will be checked against lpf_Null, but there are also places where it would be desirable to call it without having to check for the null case.

                  1 Reply Last reply
                  0
                  • M MarkB777

                    /******************************************************************************
                    FUNCTION : lpf_Null
                    DESCRIPTION : Does nothing.
                    ******************************************************************************/
                    static void lpf_Null(void)
                    {

                    }

                    Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #10

                    There is nothing wrong with an explicit "do nothing". A NOP (No Operation) instruction exists in most micro-processor instruction sets, so you can replace a normal instruction (with N bytes of code), by one or a number of NOP instructions without having to move the instructions that follow. Similarly, you can create a NOP method, so you can have an array of delegates, some of them possibly just calling your "does nothing" method. And finally, such a stub can be used to add breakpoints, logging, or whatever is appropriate in the application domain. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read formatted code with indentation, so please use PRE tags for code snippets.


                    I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                    1 Reply Last reply
                    0
                    • P Peter_in_2780

                      Agreed. State machines often need a null action when only the state transition is wanted. I've written plenty of 'em over the years, particularly in comms protocol implementations.

                      Software rusts. Simon Stephenson, ca 1994.

                      N Offline
                      N Offline
                      Niklas L
                      wrote on last edited by
                      #11

                      Peter_in_2780 wrote:

                      I've written plenty of 'em over the years

                      Has your implementation matured over the years? I bet it must be close to perfect by now! :)

                      home

                      1 Reply Last reply
                      0
                      • M MarkB777

                        No its used as a handler function in a state machine. The function is really just a bi-product of the design... but still... I thought it was funny :).

                        Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                        C Offline
                        C Offline
                        cpkilekofp
                        wrote on last edited by
                        #12

                        MarkBrock wrote:

                        No its used as a handler function in a state machine. The function is really just a bi-product of the design... but still... I thought it was funny .

                        Actually, I frequently used the same technique when I was programming in C - empty functions made good initializers for function tables, and if I wanted to track function calls all I had to do was add a trace of some sort to the empty functions.

                        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