why can't I instialize the struct member fields separately?! (In USB device driver) [on hold]
up vote
-5
down vote
favorite
I'm trying to implement usb device driver. I've wrote
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver busb;
busb.name="guru";
busb.id_table=IDtable;
busb.probe=ttlprobe(&busb,IDtable);
busb.disconnect=ttldisconnect;
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&busb);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&busb);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");
and output was this,
make -C /lib/modules/4.10.0-28-generic/build M=/home/guru/Desktop/Linuxx/Drivers/USB/check modules
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
CC [M] /home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:20:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.name="guru";
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:21:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.id_table=IDtable;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:22:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.probe=ttlprobe(&busb,IDtable);
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:23:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.disconnect=ttldisconnect;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c: In function ‘init_module’:
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:27:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int k=usb_register(&busb);
^
scripts/Makefile.build:301: recipe for target '/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o' failed
make[2]: *** [/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o] Error 1
Makefile:1524: recipe for target '_module_/home/guru/Desktop/Linuxx/Drivers/USB/check' failed
make[1]: *** [_module_/home/guru/Desktop/Linuxx/Drivers/USB/check] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
while this one works,
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={ // Defined in "/include/linux/mod_devicetable.h" which is *included* into "linux/usb.h"
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver DetectingUSB={ // Defined in /include/linux/usb.h
.name="USBtoTTL",
.id_table=IDtable,
.probe=ttlprobe,
.disconnect=ttldisconnect,
};
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&DetectingUSB);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&DetectingUSB);
}
MODULE_LICENSE("GPL");
Why I can't initialize the member fields separately?!
drivers usb usb-drive
put on hold as unclear what you're asking by roaima, Rui F Ribeiro, Jeff Schaller, mosvy, RalfFriedl 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-5
down vote
favorite
I'm trying to implement usb device driver. I've wrote
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver busb;
busb.name="guru";
busb.id_table=IDtable;
busb.probe=ttlprobe(&busb,IDtable);
busb.disconnect=ttldisconnect;
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&busb);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&busb);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");
and output was this,
make -C /lib/modules/4.10.0-28-generic/build M=/home/guru/Desktop/Linuxx/Drivers/USB/check modules
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
CC [M] /home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:20:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.name="guru";
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:21:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.id_table=IDtable;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:22:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.probe=ttlprobe(&busb,IDtable);
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:23:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.disconnect=ttldisconnect;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c: In function ‘init_module’:
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:27:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int k=usb_register(&busb);
^
scripts/Makefile.build:301: recipe for target '/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o' failed
make[2]: *** [/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o] Error 1
Makefile:1524: recipe for target '_module_/home/guru/Desktop/Linuxx/Drivers/USB/check' failed
make[1]: *** [_module_/home/guru/Desktop/Linuxx/Drivers/USB/check] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
while this one works,
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={ // Defined in "/include/linux/mod_devicetable.h" which is *included* into "linux/usb.h"
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver DetectingUSB={ // Defined in /include/linux/usb.h
.name="USBtoTTL",
.id_table=IDtable,
.probe=ttlprobe,
.disconnect=ttldisconnect,
};
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&DetectingUSB);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&DetectingUSB);
}
MODULE_LICENSE("GPL");
Why I can't initialize the member fields separately?!
drivers usb usb-drive
put on hold as unclear what you're asking by roaima, Rui F Ribeiro, Jeff Schaller, mosvy, RalfFriedl 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
1
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outsideinit_module
?
– RalfFriedl
yesterday
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
I'm trying to implement usb device driver. I've wrote
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver busb;
busb.name="guru";
busb.id_table=IDtable;
busb.probe=ttlprobe(&busb,IDtable);
busb.disconnect=ttldisconnect;
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&busb);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&busb);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");
and output was this,
make -C /lib/modules/4.10.0-28-generic/build M=/home/guru/Desktop/Linuxx/Drivers/USB/check modules
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
CC [M] /home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:20:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.name="guru";
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:21:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.id_table=IDtable;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:22:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.probe=ttlprobe(&busb,IDtable);
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:23:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.disconnect=ttldisconnect;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c: In function ‘init_module’:
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:27:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int k=usb_register(&busb);
^
scripts/Makefile.build:301: recipe for target '/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o' failed
make[2]: *** [/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o] Error 1
Makefile:1524: recipe for target '_module_/home/guru/Desktop/Linuxx/Drivers/USB/check' failed
make[1]: *** [_module_/home/guru/Desktop/Linuxx/Drivers/USB/check] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
while this one works,
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={ // Defined in "/include/linux/mod_devicetable.h" which is *included* into "linux/usb.h"
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver DetectingUSB={ // Defined in /include/linux/usb.h
.name="USBtoTTL",
.id_table=IDtable,
.probe=ttlprobe,
.disconnect=ttldisconnect,
};
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&DetectingUSB);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&DetectingUSB);
}
MODULE_LICENSE("GPL");
Why I can't initialize the member fields separately?!
drivers usb usb-drive
I'm trying to implement usb device driver. I've wrote
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver busb;
busb.name="guru";
busb.id_table=IDtable;
busb.probe=ttlprobe(&busb,IDtable);
busb.disconnect=ttldisconnect;
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&busb);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&busb);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Kumar Pugalia <email_at_sarika-pugs_dot_com>");
MODULE_DESCRIPTION("USB Pen Registration Driver");
and output was this,
make -C /lib/modules/4.10.0-28-generic/build M=/home/guru/Desktop/Linuxx/Drivers/USB/check modules
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
CC [M] /home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:20:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.name="guru";
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:21:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.id_table=IDtable;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:22:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.probe=ttlprobe(&busb,IDtable);
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:23:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
busb.disconnect=ttldisconnect;
^
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c: In function ‘init_module’:
/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.c:27:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int k=usb_register(&busb);
^
scripts/Makefile.build:301: recipe for target '/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o' failed
make[2]: *** [/home/guru/Desktop/Linuxx/Drivers/USB/check/chc.o] Error 1
Makefile:1524: recipe for target '_module_/home/guru/Desktop/Linuxx/Drivers/USB/check' failed
make[1]: *** [_module_/home/guru/Desktop/Linuxx/Drivers/USB/check] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
while this one works,
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>
struct usb_device_id IDtable={ // Defined in "/include/linux/mod_devicetable.h" which is *included* into "linux/usb.h"
{USB_DEVICE(0x067b,0x2303)},
{}
};
int ttlprobe(struct usb_interface *interface, const struct usb_device_id *id)
{
printk(KERN_INFO "Probed (%04X:%04X) devicen", id->idVendor, id->idProduct);
printk(KERN_INFO "num_altsetting : %dn",interface->num_altsetting);
return 0;
}
void ttldisconnect(struct usb_interface *interface)
{
printk(KERN_INFO "Device disconnected n");
}
struct usb_driver DetectingUSB={ // Defined in /include/linux/usb.h
.name="USBtoTTL",
.id_table=IDtable,
.probe=ttlprobe,
.disconnect=ttldisconnect,
};
int init_module(void){
printk(KERN_ALERT "intimodule exec Trying to register to USB CORE n");
int k=usb_register(&DetectingUSB);
printk(KERN_INFO "retuern value of usb_register_driver : %dn",k);
pr_info("name = %sn", THIS_MODULE->name);
pr_info("name = %sn", KBUILD_MODNAME);
return k;
}
void cleanup_module(void){
printk(KERN_ALERT "Trying to de-register to USB CORE");
return usb_deregister(&DetectingUSB);
}
MODULE_LICENSE("GPL");
Why I can't initialize the member fields separately?!
drivers usb usb-drive
drivers usb usb-drive
edited yesterday
RalfFriedl
4,9723825
4,9723825
asked 2 days ago
ganesan guru
32
32
put on hold as unclear what you're asking by roaima, Rui F Ribeiro, Jeff Schaller, mosvy, RalfFriedl 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as unclear what you're asking by roaima, Rui F Ribeiro, Jeff Schaller, mosvy, RalfFriedl 2 days ago
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
1
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outsideinit_module
?
– RalfFriedl
yesterday
add a comment |
6
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
1
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outsideinit_module
?
– RalfFriedl
yesterday
6
6
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
1
1
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outside
init_module
?– RalfFriedl
yesterday
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outside
init_module
?– RalfFriedl
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can’t initialise field members in this fashion outside a function. If you really want to do this, you’d need to move the initialisation code inside the init_module
function.
Note too that your
busb.probe=ttlprobe(&busb,IDtable);
would assign the result of ttlprobe(&busb, IDtable)
to probe
, rather than a pointer to the function which is what is expected.
Use the initialisation block, that’s what is expected here.
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can’t initialise field members in this fashion outside a function. If you really want to do this, you’d need to move the initialisation code inside the init_module
function.
Note too that your
busb.probe=ttlprobe(&busb,IDtable);
would assign the result of ttlprobe(&busb, IDtable)
to probe
, rather than a pointer to the function which is what is expected.
Use the initialisation block, that’s what is expected here.
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
add a comment |
up vote
0
down vote
accepted
You can’t initialise field members in this fashion outside a function. If you really want to do this, you’d need to move the initialisation code inside the init_module
function.
Note too that your
busb.probe=ttlprobe(&busb,IDtable);
would assign the result of ttlprobe(&busb, IDtable)
to probe
, rather than a pointer to the function which is what is expected.
Use the initialisation block, that’s what is expected here.
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can’t initialise field members in this fashion outside a function. If you really want to do this, you’d need to move the initialisation code inside the init_module
function.
Note too that your
busb.probe=ttlprobe(&busb,IDtable);
would assign the result of ttlprobe(&busb, IDtable)
to probe
, rather than a pointer to the function which is what is expected.
Use the initialisation block, that’s what is expected here.
You can’t initialise field members in this fashion outside a function. If you really want to do this, you’d need to move the initialisation code inside the init_module
function.
Note too that your
busb.probe=ttlprobe(&busb,IDtable);
would assign the result of ttlprobe(&busb, IDtable)
to probe
, rather than a pointer to the function which is what is expected.
Use the initialisation block, that’s what is expected here.
answered 2 days ago
Stephen Kitt
157k23343418
157k23343418
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
add a comment |
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
Thanks fella. I've tried and it worked out. But mine only concern is why can't I initialize the member fields outside init_module?!!
– ganesan guru
yesterday
add a comment |
6
I don't think any of the Stack sites will thank you for posting pictures of text.
– roaima
2 days ago
1
Please post text as text, so that all can read. (Blind people, robots, me, etc)
– ctrl-alt-delor
2 days ago
Now at least the question is readable, but it's a question about C, not about Linux. The answer from Stephen Kitt already explains, you can’t initialise field members outside a of function, or more general, you can't put code outside a of function. Your further comment shows lack of understanding of the general concepts. Why would you want to have your initialization code outside
init_module
?– RalfFriedl
yesterday