LinuxQuestions.org
Register a domain and help support LQ
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, 11:30 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Rep: Reputation: 50
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-18-2011, 12:31 AM   #2
paulsm4
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 01:29 PM.
 
Old 08-18-2011, 04:04 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,290

Original Poster
Rep: Reputation: 50
Thank you very much for the info. Good bye.
 
Old 08-18-2011, 01:27 PM   #4
paulsm4
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:22 AM
GNU Make - Variables as Targets Matthew Applegate Programming 11 08-09-2009 09:28 AM
virtual address of local variables dale_chip Programming 1 06-28-2007 11:56 AM
Using DDD to watch Args and Local Variables jonty_11 Programming 3 03-15-2005 01:01 PM
Local vs Global variables wujee Programming 1 03-12-2005 12:43 AM


All times are GMT -5. The time now is 05:18 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration