Skip to content

Invalid Suffix on Literal with PRId64 in C++11 #62

@smazouz42

Description

@smazouz42

Describe the bug

When compiling C/C++ code using nvcc or any C++11-compliant compiler, a warning may appear due to the usage of the PRId64 macro in printf statements. The warning:

To Reproduce

Provide code to reproduce the behavior:
test.py

a = 10
print(a)

test.cu

#include "test.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <stdbool.h>

int64_t a;
bool initialised;

/*........................................*/
void test__init(void)
{
    if (!initialised)
    {
        a = INT64_C(10);
        printf("%"PRId64"\n", a);
        initialised = 1;
    }
}
/*........................................*/

Error details

Provide the generated code, or the error message:

/home/said/Desktop/pyccel/__pyccel__/test.cu:17:16: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
   17 |         printf("%"PRId64"\n", a);

Expected behavior

This warning is triggered because C++11 requires a space between the % literal and the PRId64 macro in format strings.
A clear and concise description of what you expected to happen.

Language

cuda

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions