C Programming question

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jarekl
Posts: 17
Joined: Tue Oct 15, 2013 11:32 am

C Programming question

Post by jarekl »

Sorry this is a nube question but searching the internet and forums I find no answer.

What does this construct do:

f(USBDriver * usbp)
{
(void) usbp;
...

The entire usb driver is full of similar constructs and I just can't figure what it does.
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: C Programming question

Post by mobyfab »

The void typecast is for avoiding compiler warnings due to unused arguments.
jarekl
Posts: 17
Joined: Tue Oct 15, 2013 11:32 am

Re: C Programming question

Post by jarekl »

mobyfab wrote:The void typecast is for avoiding compiler warnings due to unused arguments.


But usbp is (?) just a pointer to a struct. There is really nothing being done. I must be missing something absolutely fundamental.
I apologize for the stupid questions. My C skills go back to '83 K&R C.
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: C Programming question

Post by mobyfab »

jarekl wrote:
mobyfab wrote:The void typecast is for avoiding compiler warnings due to unused arguments.


But usbp is (?) just a pointer to a struct. There is really nothing being done. I must be missing something absolutely fundamental.
I apologize for the stupid questions. My C skills go back to '83 K&R C.


Yes it's what I'm saying. It's just for the compiler not to complain, it does not actually do anything.
jarekl
Posts: 17
Joined: Tue Oct 15, 2013 11:32 am

Re: C Programming question

Post by jarekl »

mobyfab wrote:
jarekl wrote:
mobyfab wrote:The void typecast is for avoiding compiler warnings due to unused arguments.


But usbp is (?) just a pointer to a struct. There is really nothing being done. I must be missing something absolutely fundamental.
I apologize for the stupid questions. My C skills go back to '83 K&R C.


Yes it's what I'm saying. It's just for the compiler not to complain, it does not actually do anything.


Ok, no more questions after this (I hope)

Why would you put anything there at all then? Why not just /* .... */ ?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: C Programming question

Post by Tectu »

Through a given structure, it's required that the USBDriver is passed as a parameter to that function - why is not really important. However, the function does not use the passed argument. If you wouldn't put the (void)usbp; there, the compiler would throw a warning. So it's really just to keep the compiler happy.
Most compilers have different macros of flags to suppress those warnings anyway, but this method is just universal and will work with any C compiler.


~ Tectu
jarekl
Posts: 17
Joined: Tue Oct 15, 2013 11:32 am

Re: C Programming question

Post by jarekl »

Tectu wrote:Through a given structure, it's required that the USBDriver is passed as a parameter to that function - why is not really important. However, the function does not use the passed argument. If you wouldn't put the (void)usbp; there, the compiler would throw a warning. So it's really just to keep the compiler happy.
Most compilers have different macros of flags to suppress those warnings anyway, but this method is just universal and will work with any C compiler.


~ Tectu

Got it. Thanks.
Much Ado about nothing then. I'm sorry.
Post Reply