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

Iteration in C

Name: Anonymous 2010-06-14 3:53

Hi there /prog/.

I know Python, and I'm learning C. Both langs have for loops. Python's nicely iterates over a collection of unknown length. C's usually has you specify the length of the collection at compile time, but what if the length is unknown?

My best newbie guess: you terminate the collection with NULL, or you write an iteration function that returns some end-of-collection value when it's done.

Name: >>48 2010-06-15 14:46

>>50
You know, all I did was respond honestly to questions asked of me. Let's review: why don't I use [-1] in practice? There's lots of casting involved. Why so? Because not all of my arrays are of 32-bit elements. But because you don't like chars or shorts or doubles or structs, it's against the rules to bring up the deficiencies. Did I get that right?

To tell you the truth, I had it worked out before I was asked. The problem is that while you can use macros to alleviate cast annotations and whatnot, actually getting the length of an array is still pretty messy. It would be cleaner to use a struct. Seriously, this is just too flawed to exist in void.h.

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