Menu

#1750 Incorrect warning when using printf return value as argument

closed-fixed
5
2023-09-13
2011-01-26
Anonymous
No

When I compile the following code in SDCC, I get an incorrect warning. The compiled code might also be bad, I haven't checked it carefully.

#include <stdio.h>
void g(unsigned char x);
void h()
{
g(printf("%d", 1));
}

The command I used to compile this code is "sdcc -c test.c". I am using the latest version of SDCC: "SDCC : mcs51/gbz80/z80/ds390/pic16/pic14/TININative/ds400/hc08 3.0.1 #6138 (Jan 25 2011) (MINGW32)"

The warning message I get when compiling is:

test.c:5: warning 88: cast of LITERAL value to 'generic' pointer
from type 'int literal'
to type 'const-char generic* fixed'

This warning is incorrect. The only 'int literal' in this program is "1", and it is not being cast to a generic pointer in any way. The only generic pointer in this function is the 1st argument of printf. If I remove the call to g, changing line 5 to be "(printf("%d", 1));", then the program compiles with no warnings. If I pass an int variable in as the argument to g, the program compiles with no warnings; the function printf returns an int so I would expect my test code to compile with no warnings.

Discussion

  • Maarten Brock

    Maarten Brock - 2011-09-16

    Bug 3394118 is probably a duplicate of this bug.

     
  • Maarten Brock

    Maarten Brock - 2011-09-18

    Fixed in SDCC 3.0.4 #6855.

     
  • Maarten Brock

    Maarten Brock - 2011-09-18
    • labels: --> C-Front End
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     
  • David Grayson

    David Grayson - 2023-09-13

    Why does this say "Anonymous" created it? I think I was the one who reported it (David E. Grayson). Several of my other bug reports have the same misattribution problem.

     

    Last edit: David Grayson 2023-09-13
    • Maarten Brock

      Maarten Brock - 2023-09-13

      Hello David,

      I don't have any idea. Have you maybe registered again on SourceForge after having lost your credentials? If so, the original account may have been dissolved by SourceForge after having not been used for a long time?

      Another option could be that this information was lost in some transition of SourceForge itself in the past 12 years.

      I don't believe any of our administrators modified this and it most probably would have been registered here if it was.

      Maybe you can contact SourceForge itself about this. They have their own bug tracker.

       

Log in to post a comment.