Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
In the C language all procedures are functions. The closest analogy to a procedure is a function that returns a void type (empty value).
e.g.
void myProcedure()
{
/* do something */
}
If you want to return from a void function you just use "return;" without specifying any return value, since one is not expected by the calling function.
void myProcedure(int aValue)
{
if (aValue < 0)
return;
else
printf("aValue looks good to me: %d\n",aValue);
}
There is no need to write return. void myProcedure(int aValue)
{
if (aValue < 0)
//return; comment out
else
printf("aValue looks good to me: %d\n",aValue);
}
some compilers will actually complain.
In C, procedure is a function that returns nothing. You have to declare it as
void MyRoutine() //with or without parameter
{
...some statements...
return;
}
A function that returns nothing will return control to the caller once end of the function is reached (}), or if it encounter early return; statement. break will only exit from a loop statement, e.g.
void MyRoutine(void)
{
int i;
for(i=0; i<=100; i++){
if(i==50)
break;
...some statements...
} // End of loop
...some statements again...
} //End of function
When i reaches 50, control exits from the loop, the statements after the loop will be executed, and then control will be passed back to the caller. So break-ing will not return control to the caller unless it is placed before end of function -- which is no need if it is.
Caution: declaring a function as
MyRoutine(void);
doesn't imply that the function returns nothing, instead, the compiler assumes return type to be of type int. So you MUST declare the return type as void if that is what you meant.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.