News for hackers. Stuff that matters.
Re:Three of the Hundred Falsehoods CS Students Believe by thethirdone on Sunday November 10, 2019 @07:20PM (#21501161)
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.

Re:Three of the Hundred Falsehoods CS Students Believe by beatgammit on Sunday November 10, 2019 @07:30PM (#21501211)
Also:

> 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...

Re:Three of the Hundred Falsehoods CS Students Believe by astatine on Sunday November 10, 2019 @11:25PM (#21502142)
> > 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.

Re:Three of the Hundred Falsehoods CS Students Believe by lostcolony on Sunday November 10, 2019 @11:46PM (#21502218)
Yeah, but the likelihood of a printf throwing the timing off is generally lower than a breakpoint.
Re:Three of the Hundred Falsehoods CS Students Believe by couchand on Sunday November 10, 2019 @08:55PM (#21501532)
Sprinkling printf is very different from "good logs". Moreover, logging is not primarily for interactive debugging, but rather for monitoring. They're complimentary practices.
Re:Three of the Hundred Falsehoods CS Students Believe by chiffre01 on Sunday November 10, 2019 @09:27PM (#21501660)
I've found sprinkling print statements to be an easy and quick alternative to setting up logging.
Re:Three of the Hundred Falsehoods CS Students Believe by 0point692 on Monday November 11, 2019 @01:06AM (#21502558)
A 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.
Re:Three of the Hundred Falsehoods CS Students Believe by tahoemph999 on Sunday November 10, 2019 @07:29PM (#21501207)
Two 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.

Re:Three of the Hundred Falsehoods CS Students Believe by thethirdone on Sunday November 10, 2019 @07:41PM (#21501259)
> 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.

Re:Three of the Hundred Falsehoods CS Students Believe by ChrisSD on Sunday November 10, 2019 @07:44PM (#21501276)
Re:Three of the Hundred Falsehoods CS Students Believe by PretzelFisch on Monday November 11, 2019 @12:19AM (#21502348)
The student would not understand they can name the arguments whatever they like.
Re:Three of the Hundred Falsehoods CS Students Believe by anon946 on Sunday November 10, 2019 @10:58PM (#21502021)
I'm not sure what the original author meant, but main could have no arguments. Or, in freestanding context, may not even have a main.