Hi,
I have a few functions in my mini C library. These include printf, strlen, strcat, strncat, putchar and int/hex/oct to ASCII.
Most of these functions are very small, however, my printf has been built based on the C99 standard, and it took nearly 600 lines of code to complete.
Does this sound excessive?
When I compile to a static library, it is 47KB without optimisation.
Just wondering if this sounds normal, or too large? I imagine it will push up the size of my kernel, but maybe that's fine.
Any experience that anyone can add to this would be great.
Size of printf
Re: Size of printf
I don't see any immediate need to optimize printf, in size or in speed; until your kernel is very mature.
FYI, my test application linked with newlib is 14764 bytes:
FYI, my test application linked with newlib is 14764 bytes:
Code: Select all
#include <stdio.h>
int main ( int argc, char *argv[] ) {
printf ("Hello from user application!\n");
return 0xBADC0DE;
}
Re: Size of printf
Thankyou
No, my Kernel is non-existant. I've been spending my time building the supporting functions.
I won't worry about the size for now. At least not until it becomes an issue.
No, my Kernel is non-existant. I've been spending my time building the supporting functions.
I won't worry about the size for now. At least not until it becomes an issue.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Size of printf
my local printf backend is 567 lines without float support, so your number sounds about right. when summing the size of my strlen/str(n)cat + strto* + print (courtesy of pdclib) I end up with 17k of object files at -O0 and 15k at -O2, printf and dependencies being responsible for 8k/7k respectively so you might want to compare the designs due to the factor 3 difference observed.
Bluemoon's output seems to be in a similar league, with 14k of output code (which has a printf and its dependencies, plus a main, and probably including a runtime as well)
Bluemoon also mentioned the other important point: don't optimize prematurely. You are likely to introduce bugs that way.
Bluemoon's output seems to be in a similar league, with 14k of output code (which has a printf and its dependencies, plus a main, and probably including a runtime as well)
Bluemoon also mentioned the other important point: don't optimize prematurely. You are likely to introduce bugs that way.
Re: Size of printf
47k sounds large. My printf driver, which admittedly is not fully featured, is 2k.
If a trainstation is where trains stop, what is a workstation ?
Re: Size of printf
Is there any reasonable way to begin troubleshooting why the output file is so large?
The printf.obj file is 23KB, and the printf.asm file is 90KB (both of these created by the compiler).
The method I'm using for printf involves making a string in memory, based on the parameters passed to printf, then writing the string to screen with putchar.
Could that be the problem?
Or maybe I should create a cut down version of printf for Kernel use only, which doesn't support floating point, long long integers, etc?
The printf.obj file is 23KB, and the printf.asm file is 90KB (both of these created by the compiler).
The method I'm using for printf involves making a string in memory, based on the parameters passed to printf, then writing the string to screen with putchar.
Could that be the problem?
Or maybe I should create a cut down version of printf for Kernel use only, which doesn't support floating point, long long integers, etc?