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

Is learning C really a must for a programmer?

Name: Anonymous 2012-09-02 6:17

Many have this opinion. Somehow, by doing manual memory management allocation and garbage mangement one would become a better programmer.

I have little experience in C mainly because I can write terser and more readable code in Racket or Haskell. However I'm willing to give C a try just to learn these lessons that everybody keeps talking.

But I have a sneaking suspicion that I already know most of what is there to know. Can you list some useful lessons that a typical high level code dweller would be oblivious of?

Name: Anonymous 2012-09-04 23:27

>>70
#include <stdlib.h>
char *allocate10() {
  char array[10][12];
  return &array;
  }

char *allocate100() {
  char array[100][12];
  return &array;
}

char *allocate1000() {
  char array[1000][12];
  return &array;
}

void fill(char **array, int n) {
  int i;
  for (i=0; i < n; i++) {
    array[i] = "HAX MY ANUS";
  }
}

int main() {
  char** array;
  switch(rand() % 3) {
  case 0:
    array = allocate10();
    fill(array, 10);
    break;
  case 1:
    array = allocate100();
    fill(array, 100);
    break;
  case 2:
    array = allocate1000();
    fill(array, 1000);
    break;
  }
}

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