English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to know the following question:

"What is a function header, and what are its components?"

I would really appreciate this!

2007-05-24 06:17:19 · 5 answers · asked by yourfaceisanugget 1 in Computers & Internet Programming & Design

5 answers

A function header is made up of a name, a return type, a list of arguments, and sometimes calling convention information.

You can find some examples in standard header files. Here are two are from stdio.h:

int printf(const char *, ...);
int getchar(void);

The return type comes first -- "int" for both of these. Next comes the function name, and finally in parenthesis you have a list of arguments separated by commas. Each argument needs to have a type, but in a function header they don't need to have names.

It is important to see that the function header does NOT have any of the code for the function.

In C++, if you have a function that calls another function, the function making the call is the "caller" and the one being called is the "callee". Function headers allow you to compile the caller without compiling the callee. The callee can be compiled separately, and the caller and the callee are linked together after compiling.

// function header for a callee
void callee(void);

// implementation of a caller
void caller(void) { callee(); }


Just think of every function that uses printf. All of those callers can be compiled without needing to compile the code for printf. All you need to do is #include and you have the function header for it. You already have a compiled version of printf that came with your compiler (that's what .lib files are for).

2007-05-24 07:56:33 · answer #1 · answered by Daniel L 1 · 0 0

the function header is the indicator that the function code is below. to break it down:

first we declare a function:

Type_Returned Function_Name (Parameter_LIst);
Function_Declaration_Comment

then we define it (first line is the header):

Type_Returned Function_Name (Parameter_LIst)
{
code
code
code
}

---------example------

#include

..Function Declaration
int add (int number);
//Precondition: int number must be assiagned a value
//Postcondition: 5 is added to that number

//main program
int main()
{
using namespace std;

int number;
cout << "Please enter a number: ";
cin >> number;
cout << add(number)<
system("pause");
return 0;
}

//Function Definition
int add (int number)
{
return number+5;
}

------notes -----------

the declartion and function header are the same, except that the header does not have a ; at the end

took mark quiet a while to look or type that out, haha, he put a place holder and then went at it

you can cut and paste my code into a compiler and it will execute

the function can be as long as you want, it's like a sperate program. you just need to know what is sent and returned, they get more complicated, with arrays and call by refence parameters, but you 'll get there some other day.

functions can be on the main file or on a seperate file, for now do them in the same file, until you learn a little more.

2007-05-24 06:23:26 · answer #2 · answered by No Name 4 · 0 0

A Function prototype is a layout of what the function looks like. It lets the computer know what to expect as to the variable types that are being sent and returned from the function. You need to declare a function prototype before you call the function.

Here is an example of a function prototype I placed in a header file which is called by an INCLUDE at the top of the main C file.

// Function Declarations:
char send_byte(char myByte); //Send

And here is the funtion found in the main file:

//#pragma optimize=s 2 //no optimizatio
char send_byte(char mybyte)
{
char i; //Bit counter counts left shift 8 bits per byte
char databit; //current output bit shifted out of byte via SREG.C(arry)
char xor_rslt; //exclusive OR result
char prv_rslt; //previous result
//Process byte as long as timer doesn't over flow
//Timer overflow will scramble the output as OCR0A should have reset Timer
while(!(TIFR0 & (1< {
for(i=0; i<8; i++) //shift through each bit in mybyte
{
TCCR0B = tmr_clk_1024; //Start timer with prescale /1024
prv_rslt = 0xff; //ensure previous result will be different
//
mybyte = (mybyte<<1); //Left shift databit to SREG carry flag
if(SREG & 0x01) //must test SREG Carry flag immeadiately after shift
{
databit = (1< //of Timer Interrupt Flag B compare match to simplify XOR'ing
}
else
{
databit = 0x00; //bit == 0 will be XOR'ing a zero with the clock bit
}
//
while(!(TIFR0 & (1< {

xor_rslt = (TIFR0 ^ databit); //exclusive OR CompB Flag with DATA
xor_rslt &= (1<
if (!(xor_rslt == prv_rslt)) //update ports once per state change
{
if(xor_rslt) //send XOR resuts to I/O pin
{
tx_1; //Set Transmit Pin =1
}
else
{
tx_0; //Set Transmit Pin =0
}
prv_rslt = xor_rslt;
}

////diagnostic output of clock sig on PB1
//if(TIFR0&(1< //{
// tx_clk_1; //Set Transmit Pin =1
//}
//else
//{
// tx_clk_0; //Set Transmit Pin =0
//}

}
rst_tmr0_flags; //reset interrupt flags
}//NEXT i
return 1;//Successful
}//while not Timer over flow
return 0;//unsuccessful timer must be rinitialized to clear errors and resync
}

2007-05-24 06:23:12 · answer #3 · answered by MarkG 7 · 0 0

immediately i'm at the instant under taking a cert 4 in website layout and progression. Why in uncomplicated terms cert 4... reason you like the person-friendly certificates to permit you into the extra complicated deplomer's/honers etc. This seems to be the case for. Your going to could desire to initiate a direction someplace. with a bit of luck on the ingredient of living house reason it continually makes issues extra convenient. on the 2nd Im discovering HTML CSS JavaScript very own living house page and MySQL. initiate with the fundamentals no count number how stable you think of you're. all of them artwork and hyperlink jointly. not sure your information on how interest progression works yet even an common interest like flipping a coin has a hugh volume of script. video games that require you to stroll around and shoot take YEARS of journey as a manner to offer a stable high quality interest to no longer point out a widespread volume of script. Perks of being a student (incredibly in Australia) Is you get student costs on utility and could declare it on tax. however the colleges could have those classes so you might apply. All in all you heavily isn't waiting to flow at once for the expert coding. It purely won't artwork. The expert classes continually require a prior certificates/industry journey. Do a 6 month person-friendly direction in case you may preserve it and then head for the progression classes. stable success.

2016-11-26 23:23:00 · answer #4 · answered by ? 4 · 0 0

guessing it would name the function and maybe even declare the variables used in that function... guessing though its been years and yeasr

2007-05-24 06:23:34 · answer #5 · answered by Money Shot 3 · 0 0

fedest.com, questions and answers