seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.42k stars 74 forks source link

Unable to use C99 format macros (cannot find literal operator) #180

Open johnsonjh opened 1 year ago

johnsonjh commented 1 year ago
#define __STDC_FORMAT_MACROS 1

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

int
main(void) {
    return fprintf(stdout, "test %"PRIx32"\n", 1);
}
$ circle repro.c
error: repro.c:10:28
cannot find literal operator 'operator""PRIx32'
    return fprintf(stdout, "test %"PRIx32"\n", 1);
                           ^
johnsonjh commented 1 year ago

Since the introduction of user-defined literals, the code that uses format macro constants for fixed-width integer types with no space after the preceding string literal became invalid: std::printf("%"PRId64"\n",INT64_MIN); has to be replaced by std::printf("%" PRId64"\n",INT64_MIN);.

... so, adding the extra space does fix it. However, this shouldn't be necessary - this is happening in C mode on C files, not C++.