Timeline for Why do "modern" languages not provide argv and exit code in main?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 13, 2024 at 13:47 | comment | added | Dietrich Epp | @YannTM: The C interface is provided by the crt, not the kernel. The only way that it is part of the "OS" is if you count crt as part of the OS--which is reasonable, since it's specified by POSIX, but whether you count crt as "part of the OS" is not really the question here. The fact is that other languages (1) run on systems besides Unix and/or (2) run on Unix but without using crt. Besides--most languages don't represent strings the way C does anyway, C is kind of a weird outlier. | |
| Sep 12, 2024 at 19:33 | comment | added | Yann TM | There is no argc, but the argv parameter in C is guaranteed to have a sentinel 0x0 last argument, so argc is actually not necessary, it's a feature. The args to exec are passed as is to main, so the point stands. The C interface is what the system implements, whether you acknowledge it or not, any process created on posix comes from this system call, you must indeed go through it to create a process. | |
| S Sep 10, 2024 at 19:46 | history | suggested | Nopileos | CC BY-SA 4.0 | fixed windows code snippet since argc was unused and a non existing variable was used instead |
| Sep 10, 2024 at 16:12 | comment | added | Dietrich Epp | @YannTM: The POSIX standard describes the C interface. That C interface is provided by the C implementation on your operating system—it is not necessary to use the C interface when you are not using C. | |
| Sep 10, 2024 at 16:11 | comment | added | Dietrich Epp | @YannTM: There is no argc parameter to any of the exec() family functions. | |
| Sep 10, 2024 at 11:47 | comment | added | Yann TM | I have to downvote as the answer is factually incorrect. On linux, you create a process using fork/exec. The exec variants actually do take an argc/argv; the process has an exit status you can query when calling "wait" variants. So the POSIX (i.e. OS standard) process creation API perfectly aligns with the C main API (by design). Why this fact emerges and whether it justifies this API for C programs is debatable (more probably bad design separation as stated in other answers). On windows the command line is indeed a single line, so the answer is more realistic/correct. | |
| Sep 10, 2024 at 7:39 | review | Suggested edits | |||
| S Sep 10, 2024 at 19:46 | |||||
| Sep 10, 2024 at 7:23 | comment | added | pabouk - Ukraine stay strong | Great answer. I would just add that the C language was originally created for implementing utilities in the early Unix system. I see that as the reason why the Unix process calling interface is so integrated into C. | |
| Sep 10, 2024 at 2:47 | vote | accept | 404 Name Not Found | ||
| Sep 9, 2024 at 23:57 | history | edited | Karl Knechtel | CC BY-SA 4.0 | fix presumed typo based on the code sample (also fix apostrophe use) |
| S Sep 9, 2024 at 18:12 | review | First answers | |||
| Sep 9, 2024 at 19:02 | |||||
| S Sep 9, 2024 at 18:12 | history | answered | Dietrich Epp | CC BY-SA 4.0 |