Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PRIxPtr not recognized

Tags:

c++

gcc

I am compiling my code with gcc 4.7.0. My code compiles fine with 4.6.1. However with 4.7.0, it shows:

unable to find string literal operator ?operator"" PRIxPTR?

I have included proper inttypes.h file. If I try to redefine this, it complains that it is already defined.

Here is the erring code:

printf("%016"PRIxPTR" ", addr);

Can you tell the solution/workaround? Thanks.

like image 879
user984260 Avatar asked Apr 02 '12 19:04

user984260


1 Answers

Add a space before the PRIxPTR:

printf("%016" PRIxPTR" ", addr);
//           ^

The reason is that since gcc 4.7, user-defined literals are supported in C++11 mode. One consequence is that "%016"PRIxPTR is no longer two separate tokens, and one may define (although GCC disallows that) a user-defined literal to do something strange e.g.

size_t operator"" PRIxPTR(const char* input) { return strlen(input); }

(If you are not using C++11 mode but encounter this error, please post a bug to GCC.)

like image 111
kennytm Avatar answered Oct 13 '22 01:10

kennytm