This code:
#include <tchar.h>
TCHAR example_function() {
TCHAR example_tchar[10];
return example_tchar;
}
int main() { }
Gives error:
In function 'TCHAR example_function()':
error: invalid conversion from 'TCHAR* {aka char*}' to 'TCHAR {aka char}' [-fpermissive]
warning: address of local variable 'example_tchar' returned [enabled by default]
Your variable
example_tchar
is not aTCHAR
, but an array.What are you actually trying to achieve?
If you want to return a single
TCHAR
:If you want to return an array, or rather a pointer, you'll have to dynamically allocate memory to prevent undefined behavior: