This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] getopt.c: use integer-only function fiprintf() to save code space


Hello!

If you use getopt() (or any variant of this functionality) it pulls in fprintf() to do output to stderr in case of error. As getopt() does not deal with anything but strings or characters, it's much better to use fiprintf(), which is MUCH smaller than fprintf() - about 2.8kB for _vfiprintf_r() vs. 6.5kB for _vfiprintf_r(), not counting any support data/functions (like 4.5kB _dtoa_r()), ARMv7-M. If your program does not use fprintf() just using getopt increases the size of the executable by 20kB (size of getopt() alone is ~2kB). Let's not forget RAM use, which is smaller in fiprintf().

Actually I think that the output could be done with fputs() and fputc() only, but to do that I'd first like your opinion - there's no actual formatting (like changing the width or whatever), just displaying. This would be a bit clumsy (2-7 calls to fputs()/fputc() in place of single f[i]printf()), but still much MUCH smaller.

Regards,
FCh

Attachment: 0001-getopt.c-use-integer-only-function-fiprintf-to-save-.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]