473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

functions and main

The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ
#include <stdio.h>
int main(void){
int i = 5;
void increment(int *);
increment(&i);
printf("i = %d\n",i);
return 0;
}
void increment(int *px){
int tmp = *px;
++ tmp;
*px = tmp;
}
#include <stdio.h>
void increment(int *);
int main(void){
int i = 5;
increment(&i);
printf("i = %d\n",i);
return 0;
}
void increment(int *px){
int tmp = *px;
++ tmp;
*px = tmp;
}
Nov 14 '05 #1
10 1498
On Wed, 17 Nov 2004 06:38:56 -0600, Merrill & Michele wrote:
The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ


Yes, this is the difference between putting a function declaration in
a function (i.e. at block scope) or outside a function (i.e. at file
scope). Don't put function declarations in functions, if you do the
compiler is never required to validate the type of the declaration against
the function definition (it might anyway but it isn't required to). It is
also not where C programmers expect to find them. You won't go far wrong
if you stick to the rules

1. A static function declaration should go at or near the top of the file
where the function is defined. Some people prefer to put definition before
use to avoid the need for a declaration. That's fine too, although I like
having the declarations as a summary of the functions in the source file.

2. A non-static function declaration should be in an appropriate header
file that is included by all source files that use the function.

Lawrence

Nov 14 '05 #2

"Lawrence Kirby" <lk****@netactive.co.uk> wrote in message
news:pa****************************@netactive.co.u k...
On Wed, 17 Nov 2004 06:38:56 -0600, Merrill & Michele wrote:
The following progs differ only in the location of the prototype
(<--adjective) definition with respect to the main call. Both build and
behave for me. Is there a difference that amounts to something once the
subject matters gets stickier? MPJ


Yes, this is the difference between putting a function declaration in
a function (i.e. at block scope) or outside a function (i.e. at file
scope). Don't put function declarations in functions, if you do the
compiler is never required to validate the type of the declaration against
the function definition (it might anyway but it isn't required to). It is
also not where C programmers expect to find them. You won't go far wrong
if you stick to the rules

1. A static function declaration should go at or near the top of the file
where the function is defined. Some people prefer to put definition before
use to avoid the need for a declaration. That's fine too, although I like
having the declarations as a summary of the functions in the source file.

2. A non-static function declaration should be in an appropriate header
file that is included by all source files that use the function.

Thanks. I just violated Mr. Pop's injunction to go through K&R sequentially
and was leafing through C Unleashed. I had apologized to Mr. Summit for
printing off and binding his FAQs without giving him a cent while unaware
that I indeed had. There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ
Nov 14 '05 #3

"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ


It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.

Nov 14 '05 #4

"dandelion" <da*******@meadow.net> wrote in message
news:41***********************@dreader12.news.xs4a ll.nl...

"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ


It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.

And people stumble home from this bar from all continents? In America, we
have a homonym for foobar, and I doubt that this meaning is one a programmer
would like to have associated with his code. MPJ
Nov 14 '05 #5

"Merrill & Michele" <be********@comcast.net> wrote in message
news:Hu********************@comcast.com...

"dandelion" <da*******@meadow.net> wrote in message
news:41***********************@dreader12.news.xs4a ll.nl...

"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ
It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.

And people stumble home from this bar from all continents?
He's got lots of franchises.
In America, we have a homonym for foobar, and I doubt that this meaning is one a programmer would like to have associated with his code. MPJ


Do you mean "Fubar" Fucked Up Beyond All Repair or Failed UniBus Address
Register (on a VAX)

see http://catb.org/~esr/jargon/html/F/foobar.html
Nov 14 '05 #6


Merrill & Michele wrote:
"dandelion" <da*******@meadow.net> wrote in message
news:41***********************@dreader12.news.xs4a ll.nl...
"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ
It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.


Don't pull the newbies' legs -- they might fall off... ;-)

And people stumble home from this bar from all continents? In America, we
have a homonym for foobar, and I doubt that this meaning is one a programmer
would like to have associated with his code. MPJ


Have a look at the jargon file; the glossary provides quite a lot on
foo:
http://www.catb.org/~esr/jargon/

Apart from that, bookmark it: It will often help to understand the
gibberish in comp.*

BTW: Asking google in a nice way also would have helped you.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #7

"Michael Mair" <Mi**********@invalid.invalid> wrote in message
news:30*************@uni-berlin.de...


Merrill & Michele wrote:
"dandelion" <da*******@meadow.net> wrote in message
news:41***********************@dreader12.news.xs4a ll.nl...
"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...

There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ

It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.

Don't pull the newbies' legs -- they might fall off... ;-)


But... But... I *like* pulling legs.
Have a look at the jargon file; the glossary provides quite a lot on
foo:
http://www.catb.org/~esr/jargon/


<snigger>

Too late. I allready provided that link. It's fun, too.


Nov 14 '05 #8
Neo

"dandelion" <da*******@meadow.net> wrote in message
news:41***********************@dreader12.news.xs4a ll.nl...

"Merrill & Michele" <be********@comcast.net> wrote in message
news:r_********************@comcast.com...
There is a question I've been dying to ask though: what
the hell does 'foo' stand for? MPJ


It's the name of a popular cafe frequented by programmers: The Foo Bar,
owned by Mr Foo.


dats kOOOOOOL.....
-Neo
Nov 14 '05 #9
For a comprihensive definition of Foo have a look at RFC3092.
http://www.faqs.org/rfcs/rfc3092.html

Nov 14 '05 #10

"Prash" <pr****@rediffmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
For a comprihensive definition of Foo have a look at RFC3092.
http://www.faqs.org/rfcs/rfc3092.html

Hilarious and enlightening. I must object to the contention that the
etymology of foobar entsteht aus 'furchtbar.' So laeuft det nich. MPJ
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: [RaZoR] | last post by:
hello, main script creates IE window, put an array there and then calls a child script. chils script makes an array element equal to some object and returns control to main script. then main...
7
by: verbatime | last post by:
Please explain me how this works - or should work: Got my two classes - bcBasic (baseclass) and the derived cBasic. //--------------------------------------- class bcBasic { int number;...
12
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager,...
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
1
by: PTS | last post by:
I am working on a program that will calculate some numbers. As an example, I will say student average test score and print out the grade but my question is how do I put AVERAGE and test score and...
4
by: Ganesh Kundapur | last post by:
Hi all, suppose i have 100 functions such as f1, f2,...f100 in a single file including main. If i pass arguement to main such as $a.out f1 main should call appropriate functions. I can do this...
1
by: Jeff | last post by:
Hello everybody, I have a question concerning function declarations. When exactly do you have to declare functions if you want to use them? I have two functions main() and foo(), respectively...
7
by: Bmack500 | last post by:
I'm using visual studio 2003. I have much of my code in my main form, called 'frmMain'. When I create a class to perform string ops and such, it sometimes needs to refer to functions in the main...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
4
by: ahagley | last post by:
The problem: 1) I'm not a programmer, most of the time I'm a physicist, but I do numerical simulation. 2) I have a DLL that I want to use functions from. I have the .h file associated with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.