#defines can be handy, but remeber that you can use const ints for a lot of #define constants.......these can be preferable #define constants can make debugging difficult.
As to memory saving, with a #define, the value may be placed in the actual assembly as opposed to the CPU having to reference memory to find the value;
Code:
#define x 10
int main(void) {
int y = 10,
z;
z = x;
/* 1 instruction, value of 10 (0x0A) in instruction
mov dword ptr [ebp-8],0Ah*/
z = y;
/* 2 instructions, memory in y loaded into register, then value assigned
mov eax,dword ptr [ebp-4]
mov dword ptr [ebp-8],eax*/
return 0;
}
So I suppose you are saving efficiency of a sort.....but how eefective this is depends on what you are doing....most of the time it wont matter
For inlining of small functions they are really dodgy at times.....try this nonsense..
Code:
#include <iostream>
using namespace std;
#define defmax(a,b)(((a) > (b)) ? (a) : (b))
int main(void) {
int x = 10,
y = 11;
cout << defmax(x,y) << endl; //sensibly this will output 11..
cout << defmax(++x,--y) << endl;//x+1=11,y-1=10...11 still??...nope!!
return 0;
}
Also, such #defines as above arent type safe.....while the better option (inline functions) are.......so try stick with inlines where you can.