elliotchance / c2go

⚖️ A tool for transpiling C to Go.
MIT License
2.09k stars 155 forks source link

Unsigned format (%u) in printf() mishandled by noarch.Printf() #792

Open jcburley opened 6 years ago

jcburley commented 6 years ago

E.g. given:

#include <stdio.h>

int
main()
{
  printf("num1=%d, num2=%u\n", 3, 4);
  return 0;
}

The .go file excerpt reads:

func main() {
    noarch.Printf((&[]byte("num1=%d, num2=%u\n\x00")[0]), int32(3), int32(4))
    return
}

That looks correct enough (to me), but the resulting executable prints:

num1=3, num2=%!u(int32=4)

That should read num1=3, num2=4.

jcburley commented 6 years ago

This appears to be due to relying on fmt.Printf(), which evidently does not support %u (%d would suffice, so I've changed my code to use that). See:

https://golang.org/pkg/fmt/

kamphaus commented 5 years ago

Duplicate issue: #94