printf went and ate all my bytes ;)
photomankc
Posts: 943
I was wondering if there are some pointers on what to look at in your project when printf() starts adding in ~20KB to the code? I have other projects that include "stdio.h" and use printf with the "Simple printf" option checked and the code size stays much smaller. My current project however if I comment out any printf statements compiles to about 5.2KB, when I put the statements back in we jump back up to about 25KB using either LMM or XMMC.
Don't see an obvious difference in how I included it or used it.
Don't see an obvious difference in how I included it or used it.
/* Small test program for I2C bus driver. */ #include <stdio.h> #include <unistd.h> #include <propeller.h> #include "I2CBus.h" /** * Main program function. */ int main(void) { int addr = 0; int result = 0; I2C i2cBus(28,29,400000); sleep(2); printf("<<<< I2C Driver Test Program >>>>\n"); printf(" Bus operating on COG: %d\n\n", i2cBus.getCog()); sleep(2); printf(" Bus Scan:\n"); for (; addr < 128; addr++) { i2cBus.begin(addr); result = i2cBus.end(); printf(" I2C Address - %x", addr); if (result == 0) printf(" <--- Device Found \n"); else printf("\n"); usleep(75000); } return 0; }
Comments
As shown it compiles to 7.2KB
Comment out printf and it compiles to 2.5KB.
I think you are right, something somewhere is dragging in the full printf but I'm just not sure what since that top .cpp file in my example is the only one doing any printf-ing. I tried printing all values in decimal too but it seemed to make no difference.
Oh... Dave, I just noticed it must be your I2C code I'm tearing up from the PropBOE examples! That was a nice a springboard to start from!
For LMM use Ted's libtiny.a found here: http://forums.parallax.com/attachment.php?attachmentid=91520&d=1333953456
An XMM library has not been created for it yet. You should not expect libtiny.a to work with XMM.
To add the tiny library in SimpleIDE for LMM you have 3 options:
1) Right click a file name and "Add Library File"
2) Put libtiny.a in your project, then add -ltiny to SimpleIDE Other Library Options.
3) Put libtiny.a in a library folder and "Add Library Path" on project manager, then add -ltiny to SimpleIDE Other Library Options.
Comment that out and it's still the same. But as Dave mentions if I do only static text AND leave "Simple printf" UNCHECKED the code drops to 9.8KB If I do static text and have "Simple printf" checked it goes to 25KB. If I do ANY %d, %X stuff then checked or unchecked balloons to 25-35KB.
Odd.