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. Structure???

Structure???

Scheduled Pinned Locked Moved C / C++ / MFC
adobehelpquestion
11 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.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, I have this piece of code but I didn't write it, and I'm struggling my butt off to understand it ... can anyone help me... typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data } TFM_PARAM3; typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data void (*app_cb) (TFM_PARAM3 TfmParameters); // THIS PART I DONT UNDERSTAND } TFM_PARAM2; Many thanx...

    Regards Programm3r

    T P 2 Replies Last reply
    0
    • P Programm3r

      Hi all, I have this piece of code but I didn't write it, and I'm struggling my butt off to understand it ... can anyone help me... typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data } TFM_PARAM3; typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data void (*app_cb) (TFM_PARAM3 TfmParameters); // THIS PART I DONT UNDERSTAND } TFM_PARAM2; Many thanx...

      Regards Programm3r

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      Programm3r wrote:

      void (*app_cb) (TFM_PARAM3 TfmParameters);

      this declares a pointer to a function which gets a TFM_PARAM3 as a parameter, and returns nothing. this function pointer is called app_cb in your structure. to use it, you can do this :

      void Foo (TFM_PARAM3);

      TFM_PARAM2 myStruct;

      myStruct.app_cb = &Foo;


      TOXCCT >>> GEII power

      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

      P M 2 Replies Last reply
      0
      • P Programm3r

        Hi all, I have this piece of code but I didn't write it, and I'm struggling my butt off to understand it ... can anyone help me... typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data } TFM_PARAM3; typdef struct { uint8_t status; // status info uint8_t nrclus; // cluster uint16_t tfmtag; // tfm tag or command uint16_t recdid; // user record id uint32_t fladdr; // flash addr uint8_t *pdbuff; // ptr to bd data void (*app_cb) (TFM_PARAM3 TfmParameters); // THIS PART I DONT UNDERSTAND } TFM_PARAM2; Many thanx...

        Regards Programm3r

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #3

        Programm3r wrote:

        void (*app_cb) (TFM_PARAM3 TfmParameters); // THIS PART I DONT UNDERSTAND

        Isn't this pointer to a function returning void and taking parameter to type TFM_PARAM3, which is declared above.

        Prasad Notifier using ATL

        1 Reply Last reply
        0
        • T toxcct

          Programm3r wrote:

          void (*app_cb) (TFM_PARAM3 TfmParameters);

          this declares a pointer to a function which gets a TFM_PARAM3 as a parameter, and returns nothing. this function pointer is called app_cb in your structure. to use it, you can do this :

          void Foo (TFM_PARAM3);

          TFM_PARAM2 myStruct;

          myStruct.app_cb = &Foo;


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          P Offline
          P Offline
          Programm3r
          wrote on last edited by
          #4

          Thanx alot you guys .... :)

          Regards Programm3r

          1 Reply Last reply
          0
          • T toxcct

            Programm3r wrote:

            void (*app_cb) (TFM_PARAM3 TfmParameters);

            this declares a pointer to a function which gets a TFM_PARAM3 as a parameter, and returns nothing. this function pointer is called app_cb in your structure. to use it, you can do this :

            void Foo (TFM_PARAM3);

            TFM_PARAM2 myStruct;

            myStruct.app_cb = &Foo;


            TOXCCT >>> GEII power

            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

            M Offline
            M Offline
            MayankT
            wrote on last edited by
            #5

            toxcct wrote:

            void Foo (TFM_PARAM3); TFM_PARAM2 myStruct;myStruct = &Foo;

            Shouldn't we write: myStruct.app_cb = &Foo :confused:

            ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

            L T 2 Replies Last reply
            0
            • M MayankT

              toxcct wrote:

              void Foo (TFM_PARAM3); TFM_PARAM2 myStruct;myStruct = &Foo;

              Shouldn't we write: myStruct.app_cb = &Foo :confused:

              ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

              L Offline
              L Offline
              lemur2
              wrote on last edited by
              #6

              Yes, you're correct. You can also write: myStruct.app_cb = Foo; I think that's also in the standard rather than being a common compiler extension. Kev

              M 1 Reply Last reply
              0
              • M MayankT

                toxcct wrote:

                void Foo (TFM_PARAM3); TFM_PARAM2 myStruct;myStruct = &Foo;

                Shouldn't we write: myStruct.app_cb = &Foo :confused:

                ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                yes of course, i typed too fast and forgot to apply the .operator to the field of the structure. thanks for the notice


                TOXCCT >>> GEII power

                [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                1 Reply Last reply
                0
                • L lemur2

                  Yes, you're correct. You can also write: myStruct.app_cb = Foo; I think that's also in the standard rather than being a common compiler extension. Kev

                  M Offline
                  M Offline
                  MayankT
                  wrote on last edited by
                  #8

                  lemur2 wrote:

                  You can also write: myStruct.app_cb = Foo;

                  functions have a unique property that their value is their address i.e. &Foo == Foo not sure if this is standard... works in VC++

                  ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                  T 1 Reply Last reply
                  0
                  • M MayankT

                    lemur2 wrote:

                    You can also write: myStruct.app_cb = Foo;

                    functions have a unique property that their value is their address i.e. &Foo == Foo not sure if this is standard... works in VC++

                    ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    MayankT wrote:

                    not sure if this is standard... works in VC++

                    yes it works under microsoft compilers, but not standard. if i remember correctly, the last standard (or the future one) prevents to use the notation without the address operator...


                    TOXCCT >>> GEII power

                    [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                    M 1 Reply Last reply
                    0
                    • T toxcct

                      MayankT wrote:

                      not sure if this is standard... works in VC++

                      yes it works under microsoft compilers, but not standard. if i remember correctly, the last standard (or the future one) prevents to use the notation without the address operator...


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                      M Offline
                      M Offline
                      MayankT
                      wrote on last edited by
                      #10

                      toxcct wrote:

                      the last standard (or the future one) prevents to use the notation without the address operator...

                      this is good to remove the slight confusion... is there something planned for using function pointers as well? like: voif func () {} void (*func_ptr) (); func_ptr = &func; (*func_ptr)(); // this is clear on a function pointer being used func_ptr (); // this one is not and could be dropped (though this looks cleaner)

                      ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                      T 1 Reply Last reply
                      0
                      • M MayankT

                        toxcct wrote:

                        the last standard (or the future one) prevents to use the notation without the address operator...

                        this is good to remove the slight confusion... is there something planned for using function pointers as well? like: voif func () {} void (*func_ptr) (); func_ptr = &func; (*func_ptr)(); // this is clear on a function pointer being used func_ptr (); // this one is not and could be dropped (though this looks cleaner)

                        ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                        T Offline
                        T Offline
                        toxcct
                        wrote on last edited by
                        #11

                        i don't know for this, but i personnaly prefer calling a function (even through a function pointer) with the usual syntax. if you call a function with func_ptr() (even if the name is not that explicit), you can always browse the sources for the declaration of the func_ptr pointer, and then identify it to being a function pointer...


                        TOXCCT >>> GEII power

                        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                        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