# Thread: macro computations

1. ## macro computations

I want to use a macro definition to implement a simple conversion utility as shown here

Code:
`#define MM_TO_POINT(mm)								2.83464567*mm`
Do numerical macros store integers by default? If yes, would I need to have a type cast to a double/floating point type and rounding to achieve what I want here?

2. It's a macro -- all it does is take every occurrence of "MM_TO_POINT(bob)" and turn it into "2.83464567*bob". C will later interpret 2.83464567 as a double-precision number. But it doesn't "return" anything, it's just an expression.

3. What?

Macros are nothing more than find-and-replace rules that are done before the compiler sees the code.

This is how some example usages would be replaced:
Code:
```MM_TO_POINT(23) --> 2.83464567*23
x = MM_TO_POINT(y); --> x = 2.83464567*y;```
Now a more "interesting" case:
Code:
`x = MM_TO_POINT(a + 5); --> x = 2.83464567*a + 5;`
(This is why macro "arguments" should always be in extra brackets.)

However, macro's are a very dumb tool. Why not use a (template) function to achieve the exact same result?

Popular pages Recent additions