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

Most C programmers are faggots

Name: Anonymous 2012-01-29 19:36

I'm getting really irritated at a lot of self proclaimed C programmers for abusing the fuck out structures and pointers. It's easy to get out of hand and make your code look like shit and it seems people want to do it even when it's not necessary. The problem is even a lot of legitimately experienced C programmers do the same shit. Go look at the source to your favorite software written in C.

A good example is that stupid dubs checker thread that faggot just made. It should be written like this


#include <stdio.h>

#define base 10

int check(int i, int b) {
  return(i%b == (i/b)%b);
}

int main(void) {
  int i = 1;
 
  while(i++ < 100)
    if(check(i, base))
      puts("nice dubs bro");
     
  return(0);
}

Name: Anonymous 2012-01-30 7:44

>>36

I think quality has improved. Not all contributions needs to be from PHDs. Both implementations are a fun read, even if "wrong". There were a few really good questions and answers, and if there's a suitable trolling/discussing ratio, the community can only improve.

Compared to the wasteland of the last year, seems like a good start.

Name: Anonymous 2012-01-30 11:49

C is shit.
Use x86 asm.

Name: Anonymous 2012-01-30 11:50

>>42
x86 came from a Jew's distended anus

Name: Anonymous 2012-01-30 13:34

>>43
fuck off, faggot

Name: Anonymous 2012-01-30 15:05

>>36
Why are you upset at the thread? Is it >>1 or the replies?

Name: Anonymous 2012-01-30 15:20

>>37
I'm sorry bro, but I simply found a better way. Your method is too bloat.


#include <stdio.h>

int check(int num, int base, int k) { /*  for k 2 is dubs, 3 is trips, etc. */
  int i = 0, digit, last_digit;
 
  last_digit = num % base;
  while(++i < k) {
    digit = last_digit;
    if(digit == (num/=base)%base)
      last_digit = digit;
    else
      return(0);
  }
 
  return(1);
}

int main(void) {
  if(check(33, 10, 2)) puts("nice dubs");
  if(check(111, 10, 3)) puts("nice trips");
  if(check(15, 2, 4)) puts("nice quads");
  if(check(16, 2, 4)) puts("nice quads again");
  if(check(17, 2, 4)) puts("shouldn't print");
  if(check(12, 10, 2)) puts("shouldn't print");
 
  return(0);
}

Name: Anonymous 2012-01-30 15:27

>>46
while isn't a function
if isn't a function
return isn't a function.

Name: Anonymous 2012-01-30 15:29

>>47
see >>24

Name: Anonymous 2012-01-30 15:32

>>47
http://minnie.tuhs.org/cgi-bin/utree.pl?file=pdp11v/usr/src/cmd/ls.c
while((c=fgetc(type ? pwdfg : pwdfu)) != '\n')
if(p2->lmtime == p1->lmtime)
return(0);
U MAD?

Name: Anonymous 2012-01-30 15:53

>>37
$ cat dubs.c
#include <stdio.h>
#include <stdlib.h>
#define MAX_BASE 36

const char *alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWYZ";
const char *names[] = {
  NULL, NULL, "dubs", "trips",
  "quads", "quints", "sexts",
  "septs", "octs", "nons",
};

/* Actual dubs checking: four lines of code. */
int check(int num, int base) {
  int count = 0, digit = num % base;
  while (num % base == digit) {
    count++; num /= base;
  }
  return count;
}

int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <postnum>\n", argv[0]);
    return 1;
  }

  int postnum = atoi(argv[1]), base, result;

  if (postnum <= 0) {
    fprintf(stderr, "Invalid post number: %s\n", argv[1]);
    return 1;
  }

  for (base = 2; base < postnum && base < MAX_BASE; base++) {
    result = check(postnum, base);
    if (result < 2) continue;

    if (result >= 10) {
      printf("* %ds in base %d: ", result, base);
    } else {
      printf("* %s in base %d: ", names[result], base);
    }

    while (result--) {
      putchar(alphabet[postnum % base]);
    }
    putchar('\n');
  }

  return 0;
}

$ gcc -o dubs dubs.c && ./dubs 39
* trips in base 2: 111
* dubs in base 12: 33

Name: Anonymous 2012-01-30 16:21

>>50
nice code bro

Name: Anonymous 2012-01-30 16:21

>>36
| using pointers over array subscripts actually tends to give you a slight boost in performance
What makes you say that? Whether you dereference a pointer or use array subscript notation won't make a difference.

Name: Anonymous 2012-01-30 16:46

>>50

NOW that's some good teaching. I finally realized how the formula is working. Cool stuff, thanks.

I'm still happy that at least my bloated way works

Name: kodak_gallery_programmer !!qmiXqQhekkGXVVD 2012-01-30 16:58

>>39
>Care to explain WHY it's a "GNU bloat"?

Because when you compile a C program under the GNU C compiler, the compiler, by default, will leave on a bunch of GNU specific extensions.

Name: Anonymous 2012-01-30 16:59

>>52
Array[i] is instantly converted into *(address of the first element of the array+i) in C, behind the scenes. Dereferencing a pointer is just *(adress). If you are running along an array and increasing i each time, it is slightly more efficient to increase a pointer each time and dereference it rather than increase i each time and then add it to the pointer.

Furthermore, if you pass an array to a function what you are passing is an automatic pointer to its first element. Since you already have a pointer separate from from the one 'holding' the array, you can use it to run along the array as long as you do not need to do more than one pass over the array. Defining an additional variable to do what one you already have is capable of is wasteful in this situation.

Name: Anonymous 2012-01-30 17:06

>>55
Array[i] is instantly converted into *(address of the first element of the array+i) in C.

That only happens when you when an array is passed to a function. Otherwise no special conversion happens.

Dereferencing a pointer is just *(adress).

Again, that's incorrect.

Name: Anonymous 2012-01-30 17:06

>>54

But what if another compiler is used? The code has nothing to do with it, so it's not GNU bloat.

Name: Anonymous 2012-01-30 17:08

>>55
Also..

you already have a pointer separate from from the one 'holding' the array

I think you just need to shut your mouth on something you clearly don't understand, and like, maybe write some C code.

Name: Anonymous 2012-01-30 17:11

>>57
Try this you moron. Write a program that uses popen(). By default, when you compile it using the GNU C compiler, there will be no warnings. Now take this same piece of code and try to compile it on a Windows box.

So why would it compile do a clean build on one box and not another? It's because of the bloat GNU extensions.

Name: Anonymous 2012-01-30 17:19

>>56
>That only happens when you when an array is passed to a function. Otherwise no special conversion happens.

'In evaluating a[i], C converts it to *(a+i) immediately; the two forms are equivalent.' - K&R page 99

>Again, that's incorrect.
How so?

>>58
An array name is essentially a pointer constant.

Name: Anonymous 2012-01-30 17:23

>>60
No. An array name is the "name of an array". In C, an array and an array element are two different things.

Name: Anonymous 2012-01-30 17:27

>>61
That is implied since the elements are not constants all pointing to the first element..

Name: Anonymous 2012-01-30 17:37

>>62
No it's not you dumbass. Again, I think you just need to shut the fuck up and write some actual C code instead of googling shit.

Name: Anonymous 2012-01-30 17:38

>>62
Pstt... one is modifiable, the other one isn't. Of course the only way your dumbass would know something like this is if you would have

a)Read one of the standards.
b)Written some C code.

Name: Anonymous 2012-01-30 17:39

>>63
Its cool that you apparently know the language better than the guy who invented it and wrote the manual. That is why you don't actually need to refute the quote from the book or back any of what you are saying, right?

Name: Anonymous 2012-01-30 17:42

>>65
You're not drawing a clear distinction between an array and an array element. Now shut up. You're not only fucking stupid, but you're also fucking annoying. Now scrub another toilet you fucking mental midget.

Name: Anonymous 2012-01-30 17:43

>>65
I'm not the one making retarded statements. In your case, since you are a total fucking dumbass, I would cite either the standard or K & R. This is because you don't have the mental capacity to put this shit into your own words.

Name: Anonymous 2012-01-30 17:47

>>66
Where did I mix up an array and its elements?

>>67
Yes, you are the one contradicting K&R.

Name: Anonymous 2012-01-30 17:50

>>68
When you said the following..

>An array name is essentially a pointer constant.

Name: Anonymous 2012-01-30 17:51

>>68
Again, you're stupid. And again, you have no possible future as a computer programmer.

Name: Anonymous 2012-01-30 17:53

>>69
An array's name is used to refer to the address of its first element. It is NOT the first element. The two are distinct.

Name: Anonymous 2012-01-30 17:55

>>24

Just because the syntax for return, if, and while is similar to the syntax for function calls does not mean that they are functions. They're statements. Technically not even functions in C are really functions, they're subroutines/procedures, but that's true of most languages.

Name: Anonymous 2012-01-30 17:55

>>71
No you stupid fucker. For the second time, an "array" and an "array element" are two different things.

Name: Anonymous 2012-01-30 17:56

>>70
Show, don't tell, my dear Kodak. I gave you a direct quote from the horse's mouth. For one who admires standards so much you have not, as of yet, shown me in an official document that I am wrong. Writing angry words in my general direction will not actually prove anything beyond the fact that you are vexed.

Name: Anonymous 2012-01-30 17:56

>>71
Again, reread the passage you stupid fucker.

Name: Anonymous 2012-01-30 17:57

>>74
Again, you're a total dumbass. Now reread the passage again you mental midget.

Name: Anonymous 2012-01-30 17:58

>>73
Mother of god. A variable holding an address is not whatever lies in the address it is holding.

Name: Anonymous 2012-01-30 17:58

Also, nowhere does K & R say the following..

>An array name is essentially a pointer constant.

Name: Anonymous 2012-01-30 17:59

>>78
So, you accept you were wrong on the two other points?

Name: Anonymous 2012-01-30 18:00

>>77
>A variable holding an address is not whatever lies in the address it is holding.

Stop making up your own fucking interpretation of the language you moron.

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