473,785 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1531
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****@netacti ve.co.uk> wrote in message
news:pa******** *************** *****@netactive .co.uk...
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********@com cast.net> wrote in message
news:r_******** ************@co mcast.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*******@mead ow.net> wrote in message
news:41******** *************** @dreader12.news .xs4all.nl...

"Merrill & Michele" <be********@com cast.net> wrote in message
news:r_******** ************@co mcast.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********@com cast.net> wrote in message
news:Hu******** ************@co mcast.com...

"dandelion" <da*******@mead ow.net> wrote in message
news:41******** *************** @dreader12.news .xs4all.nl...

"Merrill & Michele" <be********@com cast.net> wrote in message
news:r_******** ************@co mcast.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*******@mead ow.net> wrote in message
news:41******** *************** @dreader12.news .xs4all.nl...
"Merrill & Michele" <be********@com cast.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**********@i nvalid.invalid> wrote in message
news:30******** *****@uni-berlin.de...


Merrill & Michele wrote:
"dandelion" <da*******@mead ow.net> wrote in message
news:41******** *************** @dreader12.news .xs4all.nl...
"Merrill & Michele" <be********@com cast.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*******@mead ow.net> wrote in message
news:41******** *************** @dreader12.news .xs4all.nl...

"Merrill & Michele" <be********@com cast.net> wrote in message
news:r_******** ************@co mcast.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

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

Similar topics

8
2352
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 script doesn't see that object and its functions. why? here is the code I implemented: //in main script
7
1811
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; virtual long myfunc(void); }
12
2092
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, so he will send us all on a conversion course. One of many reasons is that our code is littered with examples of: SUBROUTINE PRINT_ITEM(ITEM, ITEM_TYPE) IF (ITEM_TYPE .EQ. SQUARE) THEN CALL PRINT_SQUARE(ITEM)
25
5421
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 a lot are the ones that are virtual and thus will slow down the calculation, at least that is what what I have read on several places on the internet. It makes sense the program has to work with some kind off lookup table for the virtual...
1
380
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 the other parts, call the functions and where? How would I structure that program? Would I declare each function before the MAIN() function, then call them in the main. The program will read in a file and generate an output file. How do I...
4
1996
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 using switch statement, but if i have 1000 functions, then i have to write 1000 cases OR i can use pointer to functions. I am passing string to main, how to map this string to function efficiently.
1
11532
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 defined in main.c and foo.c. There is no declaration of foo() inside main.c, but main() calls foo(). If I compile both files (using gcc's -c option), and then link them, main() calls foo() without any problem. How come ? Wasn't I suppose to declare...
7
1195
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 form. However, when I use "inherits frmMain" in the class, as soon as I try to build/run the program it gives me a System.stack overflow error. No other indication of what's wrong.
21
2555
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 run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
4
3813
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 DLL, but no .def or library that I can use for static linking. I am trying to implement the GMP (GNU multiprecision library) in a large simulation code that I’ve been running on a PC, written in standard C. I’ve been using MetroWerks CodeWarrior...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.