![]() |
|
Infrequently Asked Questions in comp.lang.c |
Andrei Ellman
Member #3,434
April 2003
|
Just a bit of fun this - the comp.lang.c IAQ (Infrequently Asked Questions). [url http://www.plethora.net/~seebs/faqs/c-iaq.html] AE. -- |
Derezo
Member #1,666
April 2001
![]() |
Some of those are pretty funny. Now, anyway. "He who controls the stuffing controls the Universe" |
Evert
Member #794
November 2000
![]() |
I'm dumb!! Quote: 10.7: Can I declare main as void, to shut off these annoying ``main returns no value'' messages? (I'm calling exit(), so main doesn't return.) Certainly. You can also declare it as double. It may not compile, or it may crash, but who cares? No lousy bunch of whining lusers is going to tell you what to do.
|
CGamesPlay
Member #2,559
July 2002
![]() |
Quote:
2.3: How does struct passing and returning work? If you try to pass very large structures on the stack, you may see odd screen graphics.
So that's why my app wasn't working properly! -- Ryan Patterson - <http://cgamesplay.com/> |
Bruce Perry
Member #270
April 2000
|
Ah, good. Just what I need to fend off the newbs. Andrei, I love you. -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Quote: 1.6: I finally figured out the syntax for declaring pointers to functions, but now how do I initialize one? With the assignment operator. You were perhaps expecting a screwdriver? Heh Quote: 1.8: What's the auto keyword good for? Declaring vehicles. Ha! In C++ we can build vehicle objects from scratch! C++ IS T3H B357357!!11`1 Quote: 2.10: Can I initialize unions? Depends. They may go on strike when provoked. Luckily, if your program involves air traffic control, the ISO standard guarantees that Ronald Reagan will fire any unions that go on strike, and replace them with structs, which should be close enough.
-- |
Bruce Perry
Member #270
April 2000
|
23yrold3yrold said: Ha! In C++ we can build vehicle objects from scratch! Reinvent the wheel, why don't you. runs -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
runs down BP in his CTank: public CMilitaryVehicle: public CVehicle: public CAuto -- |
Trumgottist
Member #95
April 2000
![]() |
A public military vehicle? What is the world coming to? -- Play my game: Frasse and the Peas of Kejick |
Bruce Perry
Member #270
April 2000
|
My favourite so far: "5.9: How would I initialize an entire array from standard input? You have to use a loop. For instance, the following code reads the numbers zero through 99 into the array a. for (i = 0; i < 100; ++i) a<i> = (scanf, ("%d", i)); Make sure to include <stdio.h>, or this may not work."
-- |
Irrelevant
Member #2,382
May 2002
![]() |
Ummm... That's just nonsense. <code>//----------------//</code>Here be l33tsp33x0rz. |
Bruce Perry
Member #270
April 2000
|
No. That code works. Try it. -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Actually, no. IIRC, scanf returns the number of successfully assigned values, not the values themselves. So it would be an array of a hundred one's. -- |
Irrelevant
Member #2,382
May 2002
![]() |
Exactly. Nyah. It couldn't return the vals themselves, because then what would it return from: int foo; float bar; scanf("%i%f", &foo, &bar); Anyway, even if it did return the values, every loop it would ask you for a number and reset i. ...and you'd also get a typecasting error (from int to <b>int ). As I said, it's nonsense. S'got too many holes. It's still funny, though. <code>//----------------//</code>Here be l33tsp33x0rz. |
CGamesPlay
Member #2,559
July 2002
![]() |
"and reset i." -- Ryan Patterson - <http://cgamesplay.com/> |
Trumgottist
Member #95
April 2000
![]() |
Note the spare comma and then see the note on that FAQ entry. -- Play my game: Frasse and the Peas of Kejick |
spellcaster
Member #1,493
September 2001
![]() |
for (i = 0; i < 100; ++i) a<i> = (scanf, ("%d", i)); is equal to for (i = 0; i < 100; ++i) a<i> = i; read the code, Luke. -- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Whoops. Missed the comma. That's messed up; someone want to explain to me what's going on there? -- |
spellcaster
Member #1,493
September 2001
![]() |
What's the problem? -- |
Bruce Perry
Member #270
April 2000
|
Quote: ...and you'd also get a typecasting error (from int to int *). No you wouldn't. It's one of the optional arguments, so a plain ANSI C compiler will just take its type at face value (after doing some promotions like char,short->int and float->double). GCC will warn if you want, because it knows how scanf and similar functions are supposed to work. However, it won't do any conversions; it would be violating the ANSI C standard if it did. Don't worry guys, I didn't get it straight away either. I had to read the note too. OK, here's the deal. scanf is NOT called; all that happens is the code takes a pointer to scanf. When you get a comma, the left-hand expression is evaluated first and discarded (useful if it has a side-effect), and then the right-hand expression is evaluated. The whole expression has the value of the right-hand subexpression. Likewise, the "%d" (actually a pointer to such a string stored in read-only memory) is discarded, and the i is returned. So, give or take a couple of 'left-hand blah of comma has no effect' warnings (not an accurate quote PWNED. -- |
Andrei Ellman
Member #3,434
April 2003
|
Glad everyone seems to be enjoying the C IAQ.;D After a bit of Googling around, I have found some IAQs for some other languages. The following are also IAQs, but these are more serious than the above two. Enjoy. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Bah. the perl one is somewhat lame... but I like th atoi subroutine Or: # Q: How do I get the length of a variable? # A: Use length('$variable'); # to find out how long a variable is.
Quote: Q: Can I get a YACC grammar for the Perl language? Q: What are all those $@%* signs for? Ok Ok.. The ones near the end are pretty good... But the first few are totally lame. Quote: Q: How do I block warnings?
Quote: Q: How can I find out whether a number is odd? Q: How can I find out whether a number is even?
Those are good
Quote: Q: Perldoc isn't running properly. Where can I find the documentation? Ok.. the next one is just bad. Funny. But just wrong. Quote: Q: What's the difference between single quoted strings and double quoted strings?
-- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Quote: scanf is NOT called That's what I thought; Spellcaster confused me -- |
|