Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Small C Lib

I was generating a small project in the IDE to give some benchmarks on code size for different compiler/linker options. The program was the hello_world + the following:

double x, y, z;

printf("Hello from Nios II!\n");

x = 1.2;

y = 3.5;

z = x + y;

printf("x+y = %.02lf\n", z);

z = x - y;

printf("x-y = %.02lf\n", z);

z = x * y;

printf("x*y = %.02lf\n", z);

z = x / y;

printf("x/y = %.02lf\n", z);

When all was compiled and linked with default options, the size was 61K. So I turned on the Small C and reduce driver options in the system, and the code dropped to a waluping 18K! It looked supicious, so I looked up what you lose in the Small C. Floating point is not supported in printf. Hum! Why didn't the compiler/linker warn me. There were no errors or warnings with the above code + Small C options. What exactly did the compiler generate? Don't have a target to load it to yet, so I can't see what was generated. Just curious. I am dissapointed that I was not warned about the no support of floating point in the printf. How many other things are hidden that we are not being warned about? Thoughts....

Rick

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by rppolicy@Jan 14 2005, 09:33 AM

    i was generating a small project in the ide to give some benchmarks on code size for different compiler/linker options. the program was the hello_world + the following:

    double x, y, z;

    printf("hello from nios ii!\n");

    x = 1.2;

    y = 3.5;

    z = x + y;

    printf("x+y = %.02lf\n", z);

    z = x - y;

    printf("x-y = %.02lf\n", z);

    z = x * y;

    printf("x*y = %.02lf\n", z);

    z = x / y;

    printf("x/y = %.02lf\n", z);

    when all was compiled and linked with default options, the size was 61k. so i turned on the small c and reduce driver options in the system, and the code dropped to a waluping 18k! it looked supicious, so i looked up what you lose in the small c. floating point is not supported in printf. hum! why didn't the compiler/linker warn me. there were no errors or warnings with the above code + small c options. what exactly did the compiler generate? don't have a target to load it to yet, so i can't see what was generated. just curious. i am dissapointed that i was not warned about the no support of floating point in the printf. how many other things are hidden that we are not being warned about? thoughts....

    rick

    --- Quote End ---

    The NIOS doc does mention what is missing in the small lib!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can see the affects of using these memory footprint optimizations by looking at the Nios II Software Developer's Handbook, 4-23 (good idea to read through this part not only to find out how to reduce the footprint, but to also find out the consequences of making these changes).

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I though I was clear in my first post that I did lookup what was missing using the small c. I read 4-23 when I saw such a drastic drop in code size (full - small lib). I was just disappointed that the compiler/linker generated code without warnings when I did a fp printf.

    Rick
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Rick,

    When a function accepts a variable number of arguments, its prototype does not (and cannot) provide any information about the number and types of those variable arguments. Therefore, the usual protections do not apply in the variable-length part of variable-length argument lists: the compiler cannot perform implicit conversions or (in general) warn about mismatches

    For example with any compiler of your choosing compile up printf("Hello %d"); You will not find a compiler which points out that you're missing a parameter. If you find an example counter to this please do point it out.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    > compile up printf("Hello %d"); You will not find a compiler which points out

    > that you're missing a parameter. If you find an example counter to this please

    > do point it out.

    Well ... actually ... nios2-elf-gcc (GCC) 3.3.3 (Altera Nios II 1.0 b316) is an

    example ... provided you use -Wall . But this is irrelevant.

    > Why didn't the compiler/linker warn me.

    There were no syntax errors ... and no missing references. The compiler and

    linker performed as expected. They can't catch what amounts to an empty

    implementation/missing feature in a runtime library ...

    ... if the return value from printf() is not <= 0 with a floating point conversion

    while using small lib ... that would be a problem/bug. Otherwise, you&#39;ll have

    to stick with the library that has the features you require.

    Best Regards,

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    rugbybloke,

    Point taken - thanks. I didn&#39;t think of it as a variable length function. I&#39;m no longer disappointed in the compiler/linker, but am only disapointed in myself that I didn&#39;t think of it as a variable length function http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif . Better not quit my day job!

    Thanks again rugbybloke,

    Rick