Is it possible to use a Unicode “argv”?

后端 未结 6 1008
南旧
南旧 2021-02-07 09:48

I\'m writing a little wrapper for an application that uses files as arguments.

The wrapper needs to be in Unicode, so I\'m using wchar_t for the characters and strings I

6条回答
  •  时光取名叫无心
    2021-02-07 10:07

    In general, no. It will depend on the O/S, but the C standard says that the arguments to 'main()' must be 'main(int argc, char **argv)' or equivalent, so unless char and wchar_t are the same basic type, you can't do it.

    Having said that, you could get UTF-8 argument strings into the program, convert them to UTF-16 or UTF-32, and then get on with life.

    On a Mac (10.5.8, Leopard), I got:

    Osiris JL: echo "ï€" | odx
    0x0000: C3 AF E2 82 AC 0A                                 ......
    0x0006:
    Osiris JL: 
    

    That's all UTF-8 encoded. (odx is a hex dump program).

    See also: Why is it that UTF-8 encoding is used when interacting with a UNIX/Linux environment

提交回复
热议问题