473,486 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

function declarations, global/within a function?

Hi,

When and why would you want to...

1)
//=============================
int main(){

int someFunction(void);//declaration

someFunction();

}

int someFunction(void){} //definition

//===============================
instead of.....

2)
//==============================
int someFunction(void); //declaration
int main(){

someFunction(void);

}
int someFunction(void){} //prototype

//================================
Thanks, Douglas
Nov 14 '05 #1
2 990
mm***@yahoo.co.uk (Douglas) wrote:
When and why would you want to... int main(){
int someFunction(void);//declaration
someFunction();
}
int someFunction(void){} //definition instead of..... int someFunction(void); //declaration

int main(){
someFunction(void);
}
int someFunction(void){} //prototype


You wouldn't, really. I can't think of a single reason why
well-structured could should need that.

Richard
Nov 14 '05 #2
On Mon, 5 Jul 2004 11:54:49 UTC, mm***@yahoo.co.uk (Douglas) wrote:
Hi,

When and why would you want to...

1)
//=============================
int main(){

int someFunction(void);//declaration
This makes the prototype of someFunction only visible in main but not
aywhere in the translation unit before the definition of it occures.
someFunction();

}

int someFunction(void){} //definition

//===============================
instead of.....

2)
//==============================
int someFunction(void); //declaration
This makes the prototype of the function visible throuth the whole
translation unit beginning at this point.

int main(){

someFunction(void);

}
int someFunction(void){} //prototype

//================================
Thanks, Douglas


This makes sense whenever you have a fuction you would use only in a
specific point. Here you says in the first exapmle that only main()
should know how to call somFunction() but no other fuction that is
declared before the definition of someFunction() itself what is a
declaration on itself.

Shortening the visibility of something to the only point it is really
needed in a translation unit can help to find mistakes in coding much
earlier than in golden code. As any try outside the points where the
prototype should be known gives you a diagnostic from the compier, so
you would check if either your code or your design has a flaw long
before you starts testing.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation

Nov 14 '05 #3

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

Similar topics

3
14901
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
8793
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
5
2806
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
8
1805
by: Jim Moon | last post by:
Hi. I'm curious about this syntax: <variable>=function(){...} I'm not finding a definition of this syntax, but I see it used at this website:...
8
9599
by: Henk van Winkoop | last post by:
Hello, I debugged some html file and found this: ------------------------------------------------------------ <script language="JavaScript"> if ( some_statement ) { function MyFunction (...
4
2678
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
20
1770
by: svata | last post by:
Hello there, after some time of pondering I come to some solution which would suit me best. Please correct, if I am wrong. Function has two parameters. A string array, better said a pointer to...
1
1889
by: INeedADip | last post by:
What is the difference between: function setupGrid( param ){......} and setupGrid = function( param ){......} Are there any advantages to doing one over the other?
4
2100
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
3179
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
0
6967
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...
1
6846
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...
0
7341
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...
0
5439
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,...
1
4870
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...
0
4564
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...
0
3076
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
266
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...

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.