-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve portable ingestion of command-line arguments #66
Comments
Some relevant discussion can be found in the SG16 mailing list archives at https://lists.isocpp.org/sg16/2021/01/2005.php. Unfortunately, the list archives have predictably mojibaked the message, but the experimental results presented are still understandable. In recent discussion, Peter Brett and I discussed the following design to address command line options:
Code using this might look like the following (which would itself benefit from being wrapped in a nicer command line argument handling facility).
|
Is this also the suggested model for accessing other external input, such as environment variables or (maybe) registry-style settings? I understand the fundamental idea here is "ability to convert to path or u8string or UTF-16 or UTF-32; the implementation knows best what the lossless source encoding is and will transcode as necessary". Oh, and it seems to require quite a bit of hackery to access command-line arguments as global state in Linux, so I'd prefer a solution that uses argc and argv as-is. (Or is this lossy on Windows?) |
I think it should work for environment variables as well, but I haven't given it as much thought yet. The situation on Windows is complicated. For a program using the Microsoft C run-time, there are (at least) three sets of environment variables:
It seems clear that the implementation knows what encoding to use for each of these blocks, so it can be implementor's discretion which is used. Not losing data (due to encoding) would presumably require use of the Win32 environment block. I believe most, if not all implementations (including Windows) permit data in the environment block that is not well-formed for any particular encoding.
Not losing data on Windows would require using the |
I do recall that being cumbersome the last time I needed to access them. I believe it required reading |
An idea I had for a while
When this overload is selected
when another overload is selected, |
"putenv" does not exist in either C or C++. |
On Wed, Mar 24, 2021, 23:40 Jens Maurer ***@***.***> wrote:
"putenv" does not exist in either C or C++.
Right, that's POSIX, sorry
… —
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#66 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKX763GCB2HCQFNL6MD3GLTFJS6XANCNFSM4WOJK2YA>
.
|
Currently, C++ requires the following forms of
main()
function to be supported:Implementations can also define other additional entry points. For example, some implementations permit
main()
to accept environment variables:Some permit arguments to be accepted as wide characters; examples:
Many applications make assumptions about the encoding of the contents of
argv
(andenviron
if available). These assumptions are very rarely portable between different deployments of a single C++ implementation, let alone across multiple implementations. On some implementations individual components ofargv
andenviron
variables may have different encodings; some may not even be text. On some implementations, using the contents ofargv
may be guaranteed to lose data, and implementation-specific library functions must be use to safely access arguments.We should standardize portable ways to access data from outside the program via command-line arguments and environment variables, for example by:
main()
The text was updated successfully, but these errors were encountered: