Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of empty_guid and guid_encoder #86

Open
SBucur opened this issue May 9, 2024 · 0 comments
Open

Initialization of empty_guid and guid_encoder #86

SBucur opened this issue May 9, 2024 · 0 comments

Comments

@SBucur
Copy link

SBucur commented May 9, 2024

Writing this to mainly check if this is worth creating a merge request.

I ran into a compilation error when one of my projects was compiling a CUDA C file that inevitably #includes uuid.h. The nvcc compiler returns an error when trying to deduce the data in empty_guid and guid_encoder for CharT types:

/usr/local/include/uuid.h(298): error: a value of type "const char [37]" cannot be used to initialize an entity of type "const CharT [37]"

/usr/local/include/uuid.h(304): error: a value of type "const char [17]" cannot be used to initialize an entity of type "const CharT [17]"

What worked for me was changing the initialization of the value. At compile time, writing the rhs as a const char[37] with double quotes only deduces to a const char array. You can implicitly call std::initializer_list so the compiler deduces all types of CharT:

template <typename CharT>
inline constexpr CharT empty_guid[37] =
   {'0','0','0','0','0','0','0','0',
   '-','0','0','0','0',
   '-','0','0','0','0',
   '-','0','0','0','0',
   '-','0','0','0','0','0','0','0','0','0','0','0','0'};

template <typename CharT>
inline constexpr CharT guid_encoder[17] = 
    {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};

Regardless of how the project was configured, template initialization should be written to account for the generic type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant