Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The Challenge

Name: Lambda A. Calculus !!wKyoNUUHDOmjW7I 2013-04-20 13:08

Let's get down to business. You hate me, /prog/, and I hate you. Being a Calculus, I am unsatisfied with my programming skill and seek improvement. I challenge any of you who take pride in your skill with C to engage in the following game:

- Put down a challenge. A criteria for a program that both of us shall implement with C.
- Wait for me to accept your challenge. I don't accept those stupid challenges you find on that project euler website. Math doesn't interest me, "such that there exists"-boys. The exercises in K&R2 and, perhaps simple Unix programs, are good examples of the kinds of programs that interest me. You know, useful ones.
- Post your code.
- Wait for me to post my code.

If your program is fancier than my own and yields little criticism from one Lambda A. Calculus, I shall leave /prog/. I'm open to other stakes as well.

I await your challenges and, if any stupid stack boys want to challenge me, go for it.

Name: L. A. Calculus 2013-04-22 4:29

>>137
A negative point is that you mix statements and expressions
DAT ENTIRE LINE IS AN EXPRESSION YA RETOID.

I didn't like the misuse of the enum for some constants. An enumeration should be something countable.
A fair point, I suppose. I'm not too happy using enums myself, but I don't think there's anything better in C for this situation.

One option is to use a regular const-qualified integer type, but the disadvantage of that is that it doesn't give you a proper constant integer expression. A consequence of that, which is relevant for this program, is that you'll have a variable length array if you use it to specify the size of one.

The other, more commonly used option, is a macro. That doesn't have the disadvantage of the const-qualified integer types, but its problem is that it's more of a syntax thing. If you do the following:

#define NELEMS MAXVAL - MINVAL + 1

Whenever NELEMS is encountered it will simply be replaced with that text. It doesn't take evaluation order into account, so you need to do some yucky stuff with parentheses to account for that.

References like The Practice of Programming encourage the use of enums in favour of the other two methods (check out section 1.5 if you have that reference), and I agree that they're generally the better choice for defining magic numbers, specfically for the two reasons listed above.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List