LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-13-2005, 10:04 AM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Proper style for functions


I got a question about style. I know that this area can be dangerous because its mostly dependent on someones own personal opinion on what should be correct and what is not. I'm trying to find the best solution and make my code as best matched to the standard as possible. But enough of that lets get to my question

here is some code like i have been instructed on writing a function

Code:
 

include<stdio.h> 

void somefunction(int ,int ); 

int main() 
{
    int a,b; 

     a = 5; 
     b = 3; 

      somefunction(a,b); 


    return 0; 
} 

void somefunction(int x, int y)
{
     int z; 
      
     z = x + y;
     printf("Value is:%d\n",z); 
     
}     /* No return statement needed because there is only a void return on the fuction */

my question really is is there any reason you couldn't write the first part like this. (see below)


Code:
include<stdio.h> 

void somefunction(int x,int y )
{
    int z; 
    z = x + y; 
    printf("Value is:%d\n",z); 
} 

int main() 
{
    int a,b; 

     a = 5; 
     b = 3; 

      somefunction(a,b);

 return 0; 
}
 
Old 02-13-2005, 10:14 AM   #2
mebrelith
Member
 
Registered: Nov 2004
Location: Torreón, Coahuila, México
Distribution: Gentoo
Posts: 342
Blog Entries: 1

Rep: Reputation: 30
How you write your code (what style you follow) is up to you and what readability you want for the code. As long as it works.
 
Old 02-13-2005, 10:16 AM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
It just seams somewhat redundent to do it the first way?



what im asking is what is the proper GNU/ ANSI standard way
 
Old 02-13-2005, 10:19 AM   #4
mebrelith
Member
 
Registered: Nov 2004
Location: Torreón, Coahuila, México
Distribution: Gentoo
Posts: 342
Blog Entries: 1

Rep: Reputation: 30
The "proper" way to do it is the first one. Sorry chum
 
Old 02-13-2005, 12:07 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The first way is nice because you can declare everything up front and you don't have to make sure your functions are defined in any particular order
 
  


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
How to know if I am using mbox-style or maildir-style? Niceman2005 Linux - General 1 09-23-2005 12:08 PM
VIM-style wrapping to OpenOffice style schmmd Linux - Software 1 12-21-2004 06:50 PM
how to change mandrake style menu to kde style menu msalimane Mandriva 1 12-07-2004 01:16 PM
Proper Partition Style for Linux File System when installing Mandrake 9.2 bobsmith48 Mandriva 5 12-26-2003 07:18 PM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

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

All times are GMT -5. The time now is 07:38 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
Open Source Consulting | Domain Registration