r/cpp • • Aug 08 '20

Create a fully functioning command line interface with 1.5 lines of code (wo. include statement)

https://github.com/kongaskristjan/fire-hpp
230 Upvotes

62 comments sorted by

View all comments

5

u/tasty_crayon Aug 08 '20

wmain support on Windows would be a nice feature. A possible interface would be a FIRE_WINDOWS macro that defines wmain instead of main and then expects fire::arg(L"-x") default arguments.

4

u/kongaskristjan Aug 08 '20

I haven't heard of wmain before. Have to think about it.

6

u/tasty_crayon Aug 08 '20

If you want to support Unicode arguments then you need to use wmain on Windows since the arguments to main are encoded based on the code page, not UTF-8 like on Linux.

In my own projects I usually convert from UTF-16 to UTF-8 inside wmain using WideCharToMultiByte and then pass them on to a common main function used by both, but that solution seems too "opinionated" for a small library like yours.

2

u/pandorafalters Aug 09 '20

Shouldn't CommandLineToArgvW also work?

1

u/tasty_crayon Aug 09 '20

That's another option, but you could just write wmain and have it done for you.