Structure???
-
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
-
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
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! ]
-
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
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
-
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! ]
Thanx alot you guys .... :)
Regards Programm3r
-
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! ]
-
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.
-
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.
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! ]
-
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
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.
-
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.
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! ]
-
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! ]
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.
-
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.
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! ]