9 ms·
From the original 100 > 54. 'main' takes two arguments, argc and argv. Is this a myth because you are supposed to think of them as one argument? Or because o
by thethirdone 7y ago
From the original 100
> 54. 'main' takes two arguments, argc and argv.
Is this a myth because you are supposed to think of them as one argument?
Or because of non-standard extension that includes envp?
Or because of some other nitpick?
I feel I have a pretty solid understanding of how processes are started for C and I think the statement is true.
- tahoemph999 7y agoTwo answers. Some embedded envs I've worked in there isn't a argc/argv/envp. In the Unix envs I've worked in it also takes envp. I think I've use that 3 times in the roughly 25 years I mostly wrote c.
- thethirdone 7y ago> Some embedded envs I've worked in there isn't a argc/argv/envp. I would think you are generally using _start rather than main in embedded systems. But in embedded systems portability is generally out the window so it makes sense that some _start's call main without arguments. > In the Unix envs I've worked in it also takes envp. I think I've use that 3 times in the roughly 25 years I mostly wrote c. I have never tried to use envp and had it fail, but for maximally portable code you should use getenv() or if on posix you can use the environ variable.
- beatgammit 7y agoAlso: > Sprinkling printf is an efficient way to debug. I mostly work on threaded code, and print statements are my go to for tracking down weird timing issues. Things behave much more differently when attaching a debugger, and adding good logs makes a ton of sense long term anyway, so yeah, print statements are absolutely a great approach to debugging. A lot of them are true, but several aren't. I guess that's the thing about lists...
- couchand 7y agoSprinkling printf is very different from "good logs". Moreover, logging is not primarily for interactive debugging, but rather for monitoring. They're complimentary practices.
- chiffre01 7y agoI've found sprinkling print statements to be an easy and quick alternative to setting up logging.
- astatine 7y ago> > Sprinkling printf is an efficient way to debug. > I mostly work on threaded code, and print statements are my go to for tracking down weird timing issues. I have found printf to subtly alter timing in threaded programs. Either masking issues or introducing them. Anecdotally, I remember some programs being reported as working only with a printf present and bombing when removed.
- lostcolony 7y agoYeah, but the likelihood of a printf throwing the timing off is generally lower than a breakpoint.
- deleted 7y ago[deleted]
- ChrisSD 7y agohttps://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function https://stackoverflow.com/questions/2108192/what-are-the-val...
- anon946 7y agoI'm not sure what the original author meant, but main could have no arguments. Or, in freestanding context, may not even have a main.
- PretzelFisch 7y agoThe student would not understand they can name the arguments whatever they like.
- 0point692 7y agoA lot of the myths have built-in assumptions and I think this one is a minefield: c: (variations by spec, version); language: (variations on args to 'main', if there even is a 'main'); platform: (variations on whatever runtime implementation of 'main' you're working with). Many of these reduce to the regulatory escape hatch in finance that 'past performance does not imply future returns'. Your experience with 'main' doesn't necessarily map directly to whatever 'main' you're working with right now.