LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-17-2011, 10:30 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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?
 
Old 08-17-2011, 11:31 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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).

Last edited by paulsm4; 08-18-2011 at 12:29 PM.
 
Old 08-18-2011, 03:04 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thank you very much for the info. Good bye.
 
Old 08-18-2011, 12:27 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Local Variables anomaly!! man s Programming 4 03-22-2010 01:22 AM
GNU Make - Variables as Targets Matthew Applegate Programming 11 08-09-2009 08:28 AM
virtual address of local variables dale_chip Programming 1 06-28-2007 10:56 AM
Using DDD to watch Args and Local Variables jonty_11 Programming 3 03-15-2005 12:01 PM
Local vs Global variables wujee Programming 1 03-11-2005 11:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration