Page 1 of 1

C Programming question

Posted: Tue Oct 15, 2013 11:42 am
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.

Re: C Programming question

Posted: Tue Oct 15, 2013 12:30 pm
by mobyfab
The void typecast is for avoiding compiler warnings due to unused arguments.

Re: C Programming question

Posted: Tue Oct 15, 2013 3:58 pm
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.

Re: C Programming question

Posted: Tue Oct 15, 2013 4:05 pm
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.

Re: C Programming question

Posted: Tue Oct 15, 2013 4:17 pm
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 /* .... */ ?

Re: C Programming question

Posted: Tue Oct 15, 2013 4:23 pm
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

Re: C Programming question

Posted: Tue Oct 15, 2013 4:29 pm
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.