LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Local variables in GNU C. (http://www.linuxquestions.org/questions/programming-9/local-variables-in-gnu-c-897974/)

stf92 08-17-2011 10:30 PM

Local variables in GNU C.
 
Code:

int some_function
{
int var1;

var1=1;
return(var1);
}

int some_function
int var1;

{
var1=1;
return(var1);
}

These two examples show a local variable defined, in the 1st one, as usual. But I've seen functions written as in the second example. What is the difference?

paulsm4 08-17-2011 11:31 PM

The second is anachronistic. Don't use it - *only* use the first version (variables declared *after* the block begins), and *only* use function prototypes (parameter names and types declared within "(...)", the function signature).

stf92 08-18-2011 03:04 AM

Thank you very much for the info. Good bye.

paulsm4 08-18-2011 12:27 PM

You're welcome.

If you want more info about "K&R-style function definition", here are two useful links:

* http://stackoverflow.com/questions/1...-this-c-syntax

* http://stackoverflow.com/questions/4...nition-problem

The syntax was actually obsolete by the mid-1980's, and formally deprecated in the C89 standard.

'Hope that helps .. PSM


All times are GMT -5. The time now is 07:49 AM.