We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I came accross this code fragment when reviewing some sample code for ethernet. Didnt even try to build it. Would the delay function even be called if no executable code is in the body? I would think it would be optimized out under all circumstances? In my opionion, its not the right way to do it anyway...
Just curious ...
static void delay (void) {;}; /*--------------------------- output_MDIO -----------------------------------*/ static void output_MDIO (U32 val, U32 n) { /* Output a value to the MII PHY management interface. */ for (val <<= (32 - n); n; val <<= 1, n--) { if (val & 0x80000000) { GPIO2->FIOSET = MDIO; } else { GPIO2->FIOCLR = MDIO; } delay (); GPIO2->FIOSET = MDC; delay (); GPIO2->FIOCLR = MDC; } }
"Would the delay function even be called if no executable code is in the body?"
it depends on the compiler.
"In my opionion, its not the right way to do it anyway..."
it depends on what you want to do. you certainly CAN create delay with that. but that doesn't mean that you WILL create delay with that piece of code: you run a variety of risks with it.
whether that (taking the risk) is justified or not depends on your particular application.