Question about variable sizes in C
Hal Albach
Posts: 747
I'm working on a personal project, a roving autonomous bot I call "Slammer" for how it reacts to walls, furniture, pets, and me. The question I have, is there any advantage in propeller C to sizing variables for the maximum value that it will hold? In my project I really only need char and short variables and set them up accordingly. All well and good, program compiles without any grief, runs as expected. Then on a whim, I changed all the variables to integer and upon compiling found I had reduced the program size by about 200 bytes. Does C add extra code to manipulate the smaller variables?
Also, I'm using a serial lcd to display distances to various walls and things for "Slammer" to run over to and then run into. Finally getting the head-banging under control. With the lcd I use the dprint(...) function to send out the data. I had learned earlier that the print(....) function has a smaller sister called printi(...) which saves around 4k of program space. Again, on a whim, I replaced the dprint(...) with dprinti(...) and it worked. My code size dropped from about 12.8K to around 7.8K! Yes, I realize that I can't print floats, not an issue since I'm not using them.
Anyway, I just thought I"d pose the variable size thing and wondered why smaller variables would produce larger code.
Also, I'm using a serial lcd to display distances to various walls and things for "Slammer" to run over to and then run into. Finally getting the head-banging under control. With the lcd I use the dprint(...) function to send out the data. I had learned earlier that the print(....) function has a smaller sister called printi(...) which saves around 4k of program space. Again, on a whim, I replaced the dprint(...) with dprinti(...) and it worked. My code size dropped from about 12.8K to around 7.8K! Yes, I realize that I can't print floats, not an issue since I'm not using them.
Anyway, I just thought I"d pose the variable size thing and wondered why smaller variables would produce larger code.
Comments
The standard print functions require the floating point routines even if they're not used. The "i" equivalent routines do not reference the floating point routines.