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

Opinions on a quick C tutorial

Name: Anonymous 2013-03-17 22:03

http://wololo.net/talk/viewtopic.php?f=37&t=6236

Shoot it up and I'll let the author know.

Name: L. Arthur Calculus 2013-03-19 7:04

*TAKES A DEEP BREATH AND CALMS DOWN*

#include <stdio.h>
#include <stdlib.h>

void trick(void)
{
   printf("Magic trick!\n");
   exit(0);
}

int main()
{
   int *p = (int*)((int)&p + 0x10);
   *p = (int)&trick;
   printf("I don't know what will happen...\n");
   return 0;
}


This trick takes advantage of the way function calls are implemented by a certain compiler. If you use a compiler that implements them a different way or enable various optimisations with the same compiler, chances are it's not going to work.

Compiling such code might call "trick" successfully on one C implementation, it may give you a fancy error message telling you you're an idiot on another, or something entirely different might happen on some other one. In any case, such code yields undefined behaviour and your C implementation needn't do anything meaningful during its interpretation.

This crappy method of teaching C, perhaps similar to Zed Shaw's "Learn C the Hard Way", is based around "try something and see what happens." This may be a valid way to learn languages that have a single implementation, but you simply can't learn C like this since it's a standardised language with many different implementations.

To cut a long story short, you'd be better off reading a C reference that discusses the language rather than a certain C implementation, like K&R2. N GO REED DA FUCKIN STANDARD SO U DONT BECOME A STUPID STACK BOY.

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