Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Infrequently Asked Questions in comp.lang.c

This thread is locked; no one can reply to it. rss feed Print
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]

;D

AE.

--
Don't let the illegitimates turn you into carbon.

Derezo
Member #1,666
April 2001
avatar

Some of those are pretty funny. Now, anyway.
When I was first learning C though, that page would have been helpful! ;D

"He who controls the stuffing controls the Universe"

Evert
Member #794
November 2000
avatar

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
avatar

Quote:

2.3: How does struct passing and returning work?
The structures are put into the low part of the VGA card's VRAM. They are then removed before the next video update. This is why struct passing was not supported for a long time; VGA cards were prohibitively expensive.

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! :P

--
Tomasu: Every time you read this: hugging!

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

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

23yrold3yrold
Member #1,134
March 2001
avatar

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.

;D

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

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

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

23yrold3yrold
Member #1,134
March 2001
avatar

runs down BP in his CTank: public CMilitaryVehicle: public CVehicle: public CAuto

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Trumgottist
Member #95
April 2000
avatar

A public military vehicle? What is the world coming to?

--
"I always prefer to believe the best of everybody - it saves so much time." - Rudyard Kipling

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

;D

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Irrelevant
Member #2,382
May 2002
avatar

Ummm... That's just nonsense. :-/

<code>//----------------//</code>Here be l33tsp33x0rz.

Bruce Perry
Member #270
April 2000

No. That code works. Try it. ;)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

23yrold3yrold
Member #1,134
March 2001
avatar

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.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Irrelevant
Member #2,382
May 2002
avatar

Exactly. Nyah. :P

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 ). :P

As I said, it's nonsense. S'got too many holes.

It's still funny, though. ;D

<code>//----------------//</code>Here be l33tsp33x0rz.

CGamesPlay
Member #2,559
July 2002
avatar

"and reset i."
No, if you entered 99, it would stop the loop, if you entered <99, it would keep going.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Trumgottist
Member #95
April 2000
avatar

Note the spare comma and then see the note on that FAQ entry.

--
"I always prefer to believe the best of everybody - it saves so much time." - Rudyard Kipling

Play my game: Frasse and the Peas of Kejick

spellcaster
Member #1,493
September 2001
avatar

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.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

23yrold3yrold
Member #1,134
March 2001
avatar

Whoops. Missed the comma. :-X

That's messed up; someone want to explain to me what's going on there?

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

spellcaster
Member #1,493
September 2001
avatar

What's the problem?
scanf is called, the return value is discarded. "%d" is just a string and would return itself, if there woudln't be yet another comma which makes sure that i is returned.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Bruce Perry
Member #270
April 2000

Quote:

...and you'd also get a typecasting error (from int to int *). :P

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 ;) ), it compiles and does exactly what it says on the tin. :)

PWNED. ;D

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

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.

--
Don't let the illegitimates turn you into carbon.

Thomas Fjellstrom
Member #476
June 2000
avatar

Bah. the perl one is somewhat lame... but I like th atoi subroutine ;)

# Q: How do I convert a string to a number?
# A: Use this atoi function:

        sub atoi {
          my $t;
          foreach my $d (split(//, shift())) {
            $t = $t * 10 + $d;
          }
        }
 
        $number = atoi("123");

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?
A: Sorry, but as you must surely be aware by now, the only animals supported by Perl are ruminants such as camels and llamas. However, Yacc support may be forthcoming with version 5.007.

Q: What are all those $@%* signs for?
A: Watch your $@*$!% mouth, buddy!

Ok Ok.. The ones near the end are pretty good... But the first few are totally lame.

Quote:

Q: How do I block warnings?
A: The simplest way is to do:
close STDERR;

Quote:

Q: How can I find out whether a number is odd?
A:
sub odd {
my $number = shift;
return !even ($number);
}

Q: How can I find out whether a number is even?
A:
sub even {
my $number = abs shift;
return 1 if $number == 0;
return odd ($number - 1);
}

Those are good ;D

:o

Quote:

Q: Perldoc isn't running properly. Where can I find the documentation?
A:
perldoc perldoc

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?
A: Single quoted strings act like q(); double quoted strings act like qq().

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

scanf is NOT called

That's what I thought; Spellcaster confused me :P

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Go to: