Hi,
I am writing a c++ program for a microprocessor, and I encountered a weird problem.
I have a simple function, which does nothing else than swapping around some bytes in a 32bit integer, which is given as argument for the function.
The function looks something like this:
int swapbytes(int bts)
{
int swap_ret;
bitpnt = (char*)&bts;
swappnt = (char*)&swap_ret;
swappnt[3] = bitpnt[0];
... etc...
}
The function works fine, but the problem is, that everytime I call this function, I can see that it takes up more memory, which must mean that the compiler makes a copy of the function each time it is called. Even though it is a very small function, it takes around 250bytes extra for each time I call it.
An example:
swap1 = swapbytes(0x01020304);
swap2 = swapbytes(0x10203040);
swap3 = swapbytes(0x05060708);
This takes up 2x250 bytes more memory, than if I just called the function 1 time.
I am using a GNU compiler.
Is it a compiler problem, or do anyone know what I am dealing with here? ;-)
Thanks in advance!
Regards,
KimPiX