cancel
Showing results for 
Search instead for 
Did you mean: 

difference between Unicode::UnicodeChar and char16_t

MauFanGilaMedical
Associate III

Hello,

I've tried to reinterpret a char16_t string (specifically u"Hello")

to UnicodeChar* using

reinterpret_cast<const Unicode::UnicodeChar*>

they are the same ?

What is the difference between them ?

1 ACCEPTED SOLUTION

Accepted Solutions
Osman SOYKURT
ST Employee

Hello @MauFanGilaMedical ,

If you intend to show the text in a textArea, you don't need to use the reinterpret_cast :

    char16_t text[] = u"Hello";
 
    // This works
#if 1
    Unicode::UnicodeChar *tgfxStr = reinterpret_cast<Unicode::UnicodeChar *>(text);
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", tgfxStr);
#else
    // This also works
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", text);
#endif

 

Osman SOYKURT
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3
ferro
Lead

@MauFanGilaMedical 

I would not be surprised if it is connected to when TouchGFX was conceived - meaning pre-C++11 standard times, when char16_t was introduced. And/Or Unicode::UnicodeChar is simply easier to use.

don't know

Osman SOYKURT
ST Employee

Hello @MauFanGilaMedical ,

If you intend to show the text in a textArea, you don't need to use the reinterpret_cast :

    char16_t text[] = u"Hello";
 
    // This works
#if 1
    Unicode::UnicodeChar *tgfxStr = reinterpret_cast<Unicode::UnicodeChar *>(text);
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", tgfxStr);
#else
    // This also works
    Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%s", text);
#endif

 

Osman SOYKURT
ST Software Developer | TouchGFX