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: Anonymous 2013-03-17 22:04

Name: Anonymous 2013-03-17 23:15

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

One important thing to note is that in C everything is a number. Even a character is a number (its ASCII code is stored). This is because for computers everything are numbers too. Keep this awake in your mind forever when dealing with computers.

On a programmer's point-of-view, C distinguishes basically between 2 types of data: numbers and characters (and strings of characters). Let's begin with the numbers.

This is a rather bold claim. Though that crazy-shit ass language lets you treat just about any region of memory as containing an unrelated value, and you can seemingly cast function types (not even pointers) to goddamn longs, from a cursory glance on the standard, those values are defined to be... characters! This based on the language used to describe the memset function on the C99 standard, item §7.21.6.1.

Better refrain from trying to sum up the language's semantics as with ``everything is an x''. That's almost always wrong.

Name: Anonymous 2013-03-17 23:17

anus anus anus

Name: Anonymous 2013-03-18 0:00

>>3
One of the best arguments against making assumptions about how C implements its data types would be to look at how pcc generated C code for the PDP-10. On a word oriented machine, all the usual assumptions about how array access is done no longer hold.

Name: Anonymous 2013-03-18 1:53

Damn, I want to make vidya, but tinyscheme can't...

; tree.scm
(define (spawn h)
  (if (= 0 h)
      '()
      (cons h
            (cons (spawn (- h 1))
                  (spawn (- h 1))))))

(define (sum x)
  (if (null? x)
      0
      (+ (car x)
         (sum (car (cdr x)))
         (sum (cdr (cdr x))))))

(display (sum (spawn 23)))


$ tinyscheme tree.scm
No memory!


But lua works fine!

-- tree.lua
local function spawn(h)
    if h > 0 then
        return { n=h, a=spawn(h-1), b=spawn(h-1) }
    end
    return nil
end

local function sum(node)
    if node then
        return node.n + sum(node.a) + sum(node.b)
    end
    return 0
end

print(sum(spawn(23)))


result             time(s)
luajit-2.0.1        4.159
racket-5.3.3        4.460
lua-5.1.5          10.280
tinyscheme-1.40      :(


squirrel next?

Name: Anonymous 2013-03-18 2:10

Well, increased the static CELL_NSEGMENT, and now it runs, but takes 12.655s for n=15. :(

Name: Anonymous 2013-03-18 5:33

http://wololo.net/talk/viewtopic.php?f=37&t=6236
Not going to look. I know it is a troll thread already.

Name: Anonymous 2013-03-18 14:37

>>8
lol
EOL

Name: Anonymous 2013-03-18 15:41

>>6
Your implementation of sum is really IHNBT

Name: L. Arthur Calculus 2013-03-18 18:26

AUTHOR AINT RED DA FUCKIN STANDARD, AND I AINT RED ALL OF HIS STUPID TUTORIAL BUT LOOK AT DIS SHIT:

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

WHO DA FUCK PRETENDS A POINT IS A FUCKING int/unsigned int? DA NOOB DOESNT EVEN FUCKING CAST IT TO THOSE TYPES OR ANYTHING. IF YAIN'T CASTING TO TO A void * AND USING %p, UR DOING IT WRONG YA STUPID FUCK.

Character strings are actually pointers.

R U FUCKING STUPID? GO READ DA FUCKING STANDARD BEFORE WRITING DONKEY POOP.

Name: Anonymous 2013-03-18 19:00

>>11 s/POINT/POINTER/

N LOOK AT HOW DEY DONT EVEN CHECK DA RETURN VALUE OF malloc.  DEY CUD BE DEREFERENCING NULL POINTERS FOR ALL DA STANDARD CAREZ!

And the address being a number (an int in x86-32) we can have more fun, like:
GIT FARKED. AINT A FUCKIN int ANYWHERE YA DUMB RASCAL.

BACK WEN I WAS A BOY ALL WE HAD WAS KERNYAN AND RICKY NUMBER ONE TO LERN C FRUM, WOTS ALL DIS TUTORIAL BEES WAX ABOOT?

Name: Anonymous 2013-03-18 20:08

>>11
>>12

What about his Advanced topics? (  http://wololo.net/talk/viewtopic.php?f=37&t=10045 )

Looks interesting, I was thinking about learning from them before K&R. Just don't want to learn anything bad for me...

Name: Anonymous 2013-03-18 20:15

>>1
Powered by phpBB® Forum Software © phpBB Group
C/C++
Posts: 463
Location: The North Pole
$ apt-get install build-essential
Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
My forum: Console Heaven
My Homebrews: pyMenu 0.3.1, multiBootMenu V2, PSvid 3.0, PSP Tools 0.2


Please don't do this anymore. I just vomited all through my fucking genius keyboard.

Name: Anonymous 2013-03-18 20:20

>>6
that is fucking 2^23. try http://en.wikipedia.org/wiki/Memoization

Name: Anonymous 2013-03-18 20:23

>>15
YHBT

Name: Anonymous 2013-03-18 23:07

>>10,15
I can't post actual code on /brog/, this is just a toy example.

fucking 2^23
...and?

Name: Anonymous 2013-03-19 0:55

>>13
DONKEY EXCREMENT. HIGH CLASS DONKEY EXCREMENT. DA IDEA OF CALLING A FUNCTION WITH FANCY HACKS IS AS RELEVANT TO C AS SHOVING A CACTUS UP SOMEONE'S ANUS TO GET THEM TO SAY WORDS IS TO ENGLISH. C DONT NEED TO BE IMPLEMENTED WITH A COMPILER, JUST AS ENGLISH DONT NEED TO BE SPOKEN. AND USING A STACK AINT NECESSARY FOR A COMPILER, JUST AS HAVING A SENSITIVE ANUS THAT CAUSES YOU TO SAY WORDS AINT NECESSARY FOR SPEAKING ENGLISH.

STACK BOYS AINT RED DA FUCKIN STANDARD.

Name: Anonymous 2013-03-19 1:35

>>18
Y'know, more people would be tricked into reading your shitposts if they weren't in all caps. tl;dr, man.

Name: Anonymous 2013-03-19 2:51

>>19
Teach me your ways, oh grand manipulator of readers.

Name: L. Arthur Calculus 2013-03-19 3:13

>>19
DUMB DONKEYS CANT EVEN REED DA STANDARD

I TYPE IN CAPS WEN IM ANGRY

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.

Name: 22 2013-03-19 7:10

FUCKIN @>>13

Name: Anonymous 2013-03-19 10:23

>>22
I love you, Lambda Arthur Calculus! Please post more!

Name: Anonymous 2013-03-19 21:27

>>22

K&R also says sometimes things like: "Now try to change the variable from integer to a floating point and see what happens".

Name: Anonymous 2013-03-19 23:59

>>22
I cannot riddle this tonight. Taking the address of trick causes it to be dereferenced, because the compiler is fooled into thinking this will not produce any side effects?

Name: Anonymous 2013-03-20 0:01

>>25
Hopefully in the sense of "Say that to my face fucker and not online and see what happens".

Name: Anonymous 2013-03-20 0:55

>>25
K&R2 certainly has its flaws. It's by no means perfect, but I think it does a better job than most others for teaching the fundamentals of C. DEY DIDNT KEEP IT UP TO DATE WITH DA LATER STANDARDS CUZ DEM ISO FAT CATS JUST WANTED TO RUIN DA LANGUAGE DAT DEANIS RICKY LOVED.

>>26
It's magic. Actually, they just write the value of trick sixteen bytes ahead of where p is stored. If the author of that code were more familiar with C they'd probably have written it like this instead:

int *p;
*(void (**) (void)) ((char *) &p + 16) = trick;


But if that were so, I don't think they'd have written it in the first place.

>>27
I'm thinking about writing a C reference with a similar tone. FUKIN STACK BOYS GOTTA LEARN SOMEHOW.

Name: 28 2013-03-20 1:00

Or something like this:
*(void (**) (void)) ((char *) &p + 12 + sizeof p) = trick;

Name: Anonymous 2013-03-20 2:56

>>28
I still don't see how that results in trick being called without a call operator appearing anywhere...
(**)
That's it; I'm out.

Name: Anonymous 2013-03-20 3:09

>>30
It just takes advantage of how the C implementation performs function calls.
See http://en.wikipedia.org/wiki/Stack_frame#Structure

Name: Anonymous 2013-03-20 3:14

>>31
Ah shit, should've seen
exit(0);
that's eeevil.

Name: Anonymous 2013-03-20 4:25

When call is performed, it pushes eip (rip on 64bits) and jmp on the adress of the function called. The trick is just overwriting that return adress on the stack, so that instead of returning to the parent function (aka main) it will return to a different function, aka the trick.

Name: Anonymous 2013-03-25 19:32

Why doesn't /prog/ write a concise, yet complete and enlightening, C tutorial?

Name: Anonymous 2013-03-25 19:49

youtube.com/watch?v=psW2T4BxyYQ

Name: Anonymous 2013-03-25 19:49

youtube.com/watch?v=psW2T4BxyYQ

Name: Anonymous 2013-03-25 20:23

when will all those mental midgets finally stop writing shitty and utterly wrong tutorials about C, and go back to scrubbing toilets?
they're only misleading newcomers with their false notions of memory, representations, and whatnot.

I'm also looking at you, zed.

Name: Anonymous 2013-03-25 20:24

>>34
It's called K&R.

If you don't know C and Scheme, you don't belong here.

Name: Anonymous 2013-03-30 11:25

>>38

K&R is great, but not really concise.

The idea is something like OP's post but by an EXPERT C PROGRAMMER

Name: m0skit0 2013-04-02 3:57

Yo, really diz much tokin' 'bout mah shitty 'torials? C'mon, man...

Ok, so about the first one (http://wololo.net/talk/viewtopic.php?f=37&t=6236).

This is NOT a C tutorial, but a tutorial on programming using C as a tool. My main aim there was to introduce programming to people that know absolutely nothing about it, and link it to how a computer works at low level. Those forums are basically about PSP hacking, and as one of the authors of one of those hacks (HBL) I had to answer a lot of people wanting to start such "hackings". So I decided to write a simple tutorial about how to start programming. I think C is a good language for that kind of introduction since the audience wants low-level knowledge.

I'm by no means a C expert, although I've read K&R and the C standard, but of course I don't remember them since 1) I don't work with C professionally since 10 years now and 2) the C standard changes too fast to keep up if you don't use it daily.

And about "everything in C is a number", what I really meant was that everything in a computer is a number (and as such, ultimately everything in any programming language is a number).

Now about the other one (http://wololo.net/talk/viewtopic.php?f=37&t=10045), I'm already stating that "Please note that this tutorial is based on a 32-bit systems". I should have added that it's on x86-32 or IA32. This tricks of course could not work on different architectures, but the point again is linking C to low-level and introduce people to assembly and architecture.

Have fun!

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