This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Bug in compiler

I,ve installed the Compiler and I can,t get even the simplest code to compile properely.

Anyone know where the fix for this bug is?

Or is it a limit of the demonstration version?

void main(void)
{ cout << "Hello world!";
}

Parents
  • The interesting thing with printf - and you can see examples of it if you search this forum - is that the Keil tools are good at analyzing how you use it.

    printf() can require linking of more or less code. In this case, you didn't actually perform any "formatting", so you got a minimalistic overhead.

    The concept isn't new. Old MSDOS developers probably remember TurboC that constantly failed to print floating point numbers unless at least one floating point math function where referenced in the source. The MSDOS linkers didn't have enough information to know what formatting parameters that was used by printf.

Reply
  • The interesting thing with printf - and you can see examples of it if you search this forum - is that the Keil tools are good at analyzing how you use it.

    printf() can require linking of more or less code. In this case, you didn't actually perform any "formatting", so you got a minimalistic overhead.

    The concept isn't new. Old MSDOS developers probably remember TurboC that constantly failed to print floating point numbers unless at least one floating point math function where referenced in the source. The MSDOS linkers didn't have enough information to know what formatting parameters that was used by printf.

Children
  • The interesting thing with printf - and you can see examples of it if you search this forum - is that the Keil tools are good at analyzing how you use it.

    printf() can require linking of more or less code. In this case, you didn't actually perform any "formatting", so you got a minimalistic overhead.

    You think so?

    Integer formatting:

    #include <stdio.h>
    
    
    void main(void)
    {
       int d=1;
    
       printf("Hello world %d\n",d);
    
       while(1);
    }
    
    000003H   00035EH   00035CH   BYTE   UNIT     CODE           ?PR?PRINTF?PRINTF
    

    No formatting:

    #include <stdio.h>
    
    
    void main(void)
    {
       float f=1.0;
    
       printf("Hello world\n");
    
       while(1);
    }
    
    
    00051BH   000989H   00046FH   BYTE   UNIT     CODE           ?PR?PRINTF?PRINTF
    

    Floating point formatting:

    #include <stdio.h>
    
    
    void main(void)
    {
       float f=1.0;
    
       printf("Hello world %f\n",f);
    
    
       while(1);
    }
    
    00051BH   000989H   00046FH   BYTE   UNIT     CODE           ?PR?PRINTF?PRINTF
    

    Doesn't seem to be much analysis going on there.

  • "Doesn't seem to be much analysis going on there."

    There is obviously sufficient analysis going on to allow it to omit a load of stuff if the program uses no floating point.

    Presumably, if the program contains floating point and uses printf, the compiler cannot safely assume that there aren't any dynamically-created floating-point formats - so it just has to include them, just in case...

  • "There is obviously sufficient analysis going on to allow it to omit a load of stuff if the program uses no floating point."

    From previous experience of Microsoft compiler technologies, I would say that it is not so much analyzing that the stuff can be omitted but rather that they should not be included.

    Specifically - When floating point is required in a module, it makes reference(s) to any external functions that are required for the compiler chosen task.

    At link time these external references would normally pull in the libraries that satisfy the external references.

    So - It is not normally the formatting string of the printf that is interpreted by the compiler to determine whether the libraries that are included, but rather the fact that a floating point access is somewhere in the project.

  • There is obviously sufficient analysis going on to allow it to omit a load of stuff if the program uses no floating point.

    Yes. But that doesn't require, or imply, any analysis of the printf() calls themselves.

    Presumably, if the program contains floating point and uses printf, the compiler cannot safely assume that there aren't any dynamically-created floating-point formats - so it just has to include them, just in case.

    Indeed.