03-29-2014
The actual function code has to precede the function that calls it. So if main() is below all of the functions that main() calls, your idea will work. Functions can be coded (placed) anywhere in the source file, top or bottom of the code file.
Where all of this becomes messy is in the concept of a call tree. Well written functions do one thing very well. So it is desirable for some bit of repeated logic to be placed in a function and called from different places in the code. In this instance you could have problems with placing a function in your code physically before it gets called by another function, because it may be called in lots of others functions. The model you don't seem to like overcomes this issue. You no longer need to worry about the order of functions written in your code when you create function "prototypes". And place them near the start of the source file, before any function code.
It is typical to place all function prototypes (or whatever you wish to call them) at the very beginning of the file, after the #include section. This also allows you to place this stuff in a separate header file. That lets you then call a bunch of the code in your current code file in other C program files. This is the idea behind a code library: DRY coding - don't repeat yourself. Write a function once, use it forever.
Linking them is beyond the scope of this little message.
These 2 Users Gave Thanks to jim mcnamara For This Post:
8 More Discussions You Might Find Interesting
1. Programming
in the header file orville.h, outside of the #ifdef #endif , there is the following
#define JOB_CONTROL /* support job-control */
As you can see, the JOB_CONTROL macro has no value associated with it. Here is what I go when I ran grep on the entire source code.
$ grep -iR... (6 Replies)
Discussion started by: frequency8
6 Replies
2. UNIX for Dummies Questions & Answers
Hi friends,
I am not sure if perl questions can be raised here. :rolleyes:
But I have a doubt if there is a way to do "#define" in perl, like in C.
Does anyone know if it is feasible (without CPAN modules)?
Thanks,
Srini (7 Replies)
Discussion started by: srinivasan_85
7 Replies
3. Programming
Hello,
I would like to conditionaly comment in my code source some fields from arrays. So I use the property ## from the #define definition.
my code:
...
#define slet /##*
#define etsl *##/
...
const T_SVT_ADLL_A653_DESC A_DESC =
{
{ slet qwerty etsl SLICING,... (3 Replies)
Discussion started by: cypleen
3 Replies
4. Programming
if i do this in C
#define NUM 1234512345
then how come i cant print it out using
int main(int argc, char **argv) {
printf("%d\n", NUM);
return 0;
}
well the result is -1219236538, why isnt it 1234512345 ? (7 Replies)
Discussion started by: omega666
7 Replies
5. Programming
Hi,
I had a head file, looks like
#define MIN_NUM 10
#define MAX_NUM 10
is there any way to get "MAX_NUM" from 10?
thanks.
peter (9 Replies)
Discussion started by: laopi
9 Replies
6. Shell Programming and Scripting
I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line
if
then... (8 Replies)
Discussion started by: saku
8 Replies
7. Shell Programming and Scripting
HI
I have file A.txt
_1A
_2A
_3A
_4A
I want define all as different variable.
$1A=_1A
$2B=_2A
$3C=_3A
$4D=_4A
Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies
8. Shell Programming and Scripting
Hi,
I just define the variable in script and use those script in another script but the variable not recognize.
test1.sh
#!/bin/bash
DB="test_db"
USR="test_user"
PWD="test_pwd"
HST="24.254.87.12"
test2.sh
#!/bin/bash
./test1.sh
mysql -u $USR -p $PWD -h $HST... (2 Replies)
Discussion started by: fspalero
2 Replies