Elektrine lite

← Feed

@aurisc4@floss.social

Post #2450113

2026-05-05 12:59 UTC

Never before have I though of this. In C/C++ signature for main is: int main(int argc, char **argv); (yeah, there is also env version). Note that argv is pointer to pointer where neither pointer is const. You can modify the thing! Tried using clang on Mac, modifying argv[0] or argv[0][0] works. #programming #Cpp

Replies (1)

  • @sjmulder@bsd.network 2026-05-14 21:22

    @aurisc4@floss.social in fact GNU libc getopt() reorders argv to move the options forward, so that the "argc -= optind; argv += optind;" trick to keep just the positional arguments keeps working. (Classic getopt() stops at the first non-option argument, an optional behaviour for glibc)

    Open ##2569967