1: and probably the best - use the correct optimizer settings for the best compiler you can find. SOme compilers are great at size optimizations. Also, C and C++ can be trimmed down by writing smart code. Avoid virtual function, use the smalles type, possible, use individual bit instead of bool, avoid templates and printf, etc. . Also, get a good compiler that throws dead code out and reuses duplicate strings.
2: actually compress you code in ROM, using gz, zip, bz2 or whatever, and unpack your code into RAM when you need it. If you don't mind the pain and have limited RAM, you can page sections of code into RAM as needed.
3: use an interpreter. I am not kidding. In some cases, using an interpreter on precompield code (similar to Java and a virtual machine) can minimize your overall code. On a Basic stamp, for example, you can write useful programs in 256 byte flash RAM using PicBASIC in the ROM. This depends of course on your interpreter and the size of the required library.
The locator of On Time RTOS-32 can compress code which is then expanded to RAM at boot time. The compressed code typically has a size of 50% of the original code, so you could run a 256k code segment with just 128k ROM (assuming you don't have too much inialized data which is also decompressed from ROM to RAM).
More information and a free downloadable test version of On Time RTOS-32 is available at
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.