Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Understanding variable declaration & function in C++

Status
Not open for further replies.

eebhoi01

Advanced Member level 4
Full Member level 1
Joined
Feb 22, 2012
Messages
116
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,347
Hello,

I am confused with this, can someone please help me understand how this following cases in declaration of variable differ?

1. uint8_t variable (uint8_t value)

2. uint8_t variable (uint8_t value1, uint8_t value2)


Another is, how does this function differ from each other?

void main() {
}

and

int main (void){
}

Thank you for your time guys, I am looking forward for someone who could enlighten me on this. Thank you.
 

"void main" means the main function (often the whole program) "returns no value"
"int main" means it returns an integer value when it finishes.

Note that in the case of an embedded program which does not have an operating system, returning any value is pointless as there is nothing to return it to. In the case of a program running on a PC for example, where it terminates and returns to the OS, the value is usually used to indicate success or the reason for failing.

Brian.
 
1 and 2 are function rather than variable declarations. They differ by the number of arguments.
 
1 and 2 are function rather than variable declarations. They differ by the number of arguments.

Sir, follow up question.

Suppose I create a function that says:

uint32_t A (uint8_t B), does this means that A function will return B B B B of data? Or say since the function is to return A which is 32 bit that is consist with 4x8 bit of B?
I'd like to have a grasp on how will this returned 32bit A becomes given it has an argument of 8bit B.

I hope my questions is clear enough. Thanks
 

A function returns the size of data you specified when you created it. So 'uint32_t A' means the function called 'A' returns ONE 32-bit result. Whether you interpret that as one 32 bit value or four 8 bit values depends on how you use it in your program. You can only return one value though, the result can not be four different 8 bit results. If you need to return more than one value from a function, the best method is to pass the address where the results should be stored to the function so it can save the values there.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top