Skip to main content
MauFanGilaMedical
Associate III
May 6, 2026
Solved

difference between Unicode::UnicodeChar and char16_t

  • May 6, 2026
  • 2 replies
  • 156 views

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 ?

Best answer by Osman SOYKURT

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

 

2 replies

ferro
Lead
May 6, 2026

@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.

MauFanGilaMedical
Associate III
May 8, 2026

don't know

Osman SOYKURT
Technical Moderator
May 11, 2026

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 SOYKURTST Software Developer | TouchGFX