| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Apr 07, 2008 7:45 pm Post subject: macros vs functions |
|
|
This is something really simple. But I just learned macros (=P), and I was thinking if I should use them if I were to make a REALLY SIMPLE calculator. Like if they use less memory than functions do or something. Like
| Code: |
#define mult(z) ((x) * (y))
|
or...
| Code: |
int mult(int x, int y)
{
return x*y;
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Apr 07, 2008 7:51 pm Post subject: |
|
|
Macros are better for speed, but increase the size.
Functions are better for size, but decrease the speed slightly due to all the push/pop/call stuff.
Also, if it is an extremely small macro like above, the macro would take less space than the function.
Last edited by Flyte on Mon Apr 07, 2008 7:51 pm; edited 1 time in total |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Apr 07, 2008 7:51 pm Post subject: |
|
|
when u call a function your pushing information onto the stack, doing your calculations then poping them off the stack (i think, correct me if im wrong)
while a definition is just replacing the word defined, with the code that you have as the definition.
So definitions for smaller procedures such as multiplications would probly be more benificial.
Correct me if im wrong, its just general computing knowledge so im not completely sure.
Edit: dam, flyte beat me to it , by a couple seconds.
_________________
|
|
| Back to top |
|
 |
|