Can it work?

G

gvutcc

// for ANSI/UNICODE


#ifdef UNICODE
#define $ L
#else
#define $
#endif /* UNICODE */


// use it
wsprintf($"hello");

Can it work?
Is it a good idea?
 
U

Ulrich Eckhardt

// for ANSI/UNICODE
#ifdef UNICODE
#define $ L
#else
#define $
#endif /* UNICODE */
// use it
wsprintf($"hello");

Can it work?

Not like that. You might want to see how it's done for the win32 API. Other
than that, wsprintf will never take a char string. And never only one
argument. I assume that was just an ill-chosen example.
Is it a good idea?

No. The way the win32 API works and the way you have to work with it is
pretty fucked up, so I wouldn't redo it. In particular when some piece of
your code suddenly changes meaning depending on a preprocessor definition
it is simply annoying. I only see two good ways for flexible i18n: use
char and switch between different charsets (remember, with UTF-8 you have
full Unicode range available!) via the locale or use wchar_t internally
and only convert accordingly when doing IO.

If you need to really do it like that, you could still write your own
preprocessor or use sed/awk/perl whatever.

Uli
 
K

Kenneth Brody

Walter said:
No and No.

$ is not part of the basic C character set. You cannot define
a macro with $ in the name.

What about something like:

#ifdef UNICODE
#define L(str) L ## str
#else
#define L(str) str
#endif

...

wsprintf(L("hello"));

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top