Originally Posted by
NumLock
Potentially a ridiculous newbie question, but here goes
Just for fun I was running the "man gcc" command on my linux machine. I must admit I had never expected the gcc compiler to have that many options for doing this and that and seemingly everything. So I started thinking what would the gcc code that deals with command-line user input look like. Are there like a thousand if or switch statements in there for every "gcc -xx" option ? How are such programs written in real life, meaning not study projects and such. Is it usual in real life programming to have code with a thousand, two thousand or nine thousand if or switch statements (supposing there are nine thousand possibilities to process), or are such problems dealt with in other ways?
I am just curious, but if anyone has any ideas, I would be happy to hear them
As the others have already pointed out (indirectly) comparing something as complex as GCC to your average user program is decidedly not a good idea. Compilers tend to live in and come from a world all their own.
Yes there are user programs (esp. for Windows GUI mode) that can and do have hundreds or even thousands of settings. For the most part these are not passed as command line arguments. Instead they are stored in initialization (.INI) files or the system registry (or linux equivalent thereof) and are loaded into structs, arrays, and/or bitfields for runtime use. It is very common to see statements like...
Code:
if (range < 30 && setting.safety == 1)
DisableCannon();
scattered all through source code. There's not much to do with an option once it's loaded so most programmers tend to deal with them as they encounter them.