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.
>>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:
Anonymous2013-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))))))
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.
>>10,15
I can't post actual code on /brog/, this is just a toy example.
fucking 2^23
...and?
Name:
Anonymous2013-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.
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.
>>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:
Anonymous2013-03-20 0:01
>>25
Hopefully in the sense of "Say that to my face fucker and not online and see what happens".
Name:
Anonymous2013-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:
>>31
Ah shit, should've seen exit(0);
that's eeevil.
Name:
Anonymous2013-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:
Anonymous2013-03-25 19:32
Why doesn't /prog/ write a concise, yet complete and enlightening, C tutorial?
Name:
Anonymous2013-03-25 19:49
youtube.com/watch?v=psW2T4BxyYQ
Name:
Anonymous2013-03-25 19:49
youtube.com/watch?v=psW2T4BxyYQ
Name:
Anonymous2013-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.
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.
Some posts in this thread could still be taking into account for improving your tutorial, though. Beneath all the peculiarities, there are some knowledge people around here.
Also, if you can bear all the trolling, you might even enjoy this place. Most of us are LISP lover; Knights of the Lambda Calculus.
>>43
You and I both know that >>40 disregards these posts, probably thinks he is better than average /prog/rider, and will never participate in such an orgy that 4chan/prog is.
I do not disgregard these posts, otherwise I wouldn't have answered, nor I do think I'm better programmer than anyone (like some comments here definitely do). I just try to do my best and share my limited knowledge.
This said, I'm in no mood for for sexually frustrated assholes like >>44 and the likes, that hide under cyberanonimity can insult people without being punched in da face.
Anyway, have a nice day everyone, gotta some awful programming to do.
Name:
Anonymous2013-04-03 5:26
>>45
You are also protected by your own cyberanonimity from being punched in da face. As am I, for now.
Name:
Anonymous2013-04-03 6:11
>>45
go fuck yourself with a rake you subhuman piece of shit, die in a fire
>>46>>47>>48>>49
Stop trying to make it look like you're several different people, you racist anti-semitic fatto. Get a fuckin' life and stop F5-ing... I'll tell you a lil' secret: there's real life besides your screen. Even a human kind of person named "GIRL". Yeah, trust me, just go outside... don't hurt yourself with the sun though.
And have fun!
Name:
Anonymous2013-04-09 6:12
[QUOTE]This is NOT a C tutorial, but a tutorial on programming using C as a tool.[/QUOTE]
WELL IT AINT RIGHT.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *a = (int*) malloc(sizeof(int)); // Allocating sizeof(int) bytes of space
int b = 2251;
*a = b; // Copying content of b to a
printf("%d\n", *a);
free(a); // Free a's reserved memory
return 0;
}
YOU WAIT FOR DAT BAD BOY malloc TO RETURN A NULL POINTER N SEE WAT HAPPENS. IT'S LIKE TEACHIN' PEOPLE TO USE A HACKSAW AND CHOPPING OFF YOUR DOODLE WHEN UR TRYING TO CHOP OFF A PIECE OF WOOD. YA DON'T DEREFERENCE NULL POINTERS JUST AS YOU DON'T CHOP OFF YOUR DOODLE.
N WAT ABOUT DAT KOOL HACK FOR CALLING A FUNCTION? DAS LIKE SAYING: "WANT A FISH? WELL, WE HAVE PLENTY OF FISH OVER HERE THAT YOU COULD TAKE, SURE, BUT I SUGGEST WALKING INTO THAT FUCKING VOLCANO AND FINDING A FISH IN THERE. IT'LL BE KOOL."
[QUOTE]I think C is a good language for that kind of introduction since the audience wants low-level knowledge.[/QUOTE]
AINT NO LOW-LEVEL COOKIE-CUTTER LANGUAGE.
[QUOTE]I'm by no means a C expert, although I've read K&R and the C standard,[/QUOTE]
YAINT RED DA FUCKIN STANDARD. I CAN FUCKIN TELL. I WALK INTO A ROOM AND IMMEDIATELY I KNO WHO'S RED DA STANDARD N WHO HASN'T. JUST CUMS NATURALLY FOR ME. YOU SIR, YOU MAY HAVE TAKEN A FEW GLIMPSES OF DA STANDARD, BUT U SURE AS HELL AINT RED IT.
[QUOTE]C standard changes too fast to keep up if you don't use it daily.[/QUOTE]
ONCE A FUKIN DECADE. YA CUDDA KEPT IT ANSI C; COMPLIANT WIT DA STANDARD DEANIS RICKY LOVED, IF DA LATER STANDARDZ ARE A PROBLEM FER YA AS DEY WERE FOR DEANIS RICKY WHO DID HIMSELF IN OVER THE CHANGES IN C11.
LAMBDA ARTHUR FUCKING CALCULUS SIGNING OFF!
Name:
Anonymous2013-04-09 6:12
O SHIT DER ARENT QUOTE TAGS ON HERE R DER? FERGOT ME GREETER DEN
>>53
IVE BEEN QUOTIN WITH GREATER-THANS SINCE BEFORE YOU WERE BORN U DUM NOOB. IM JUST GETTING FORGETFUL IN MY OLD AGE. SHOW SUM RESPECT FOR UR ELDERS.
>>55
I BEEN SHOUTIN AT PEOPLE SINCE BEFORE U WERE BORN U DUM NOOB. IF I WANNA SHOUT IM GUNNA SHOUT! I BET UR ONE OF THOSE ISO HYENAS DAT KICKED ME OUT OF DA C COMMITTEE FOR SHOUTIN AT SUM FUCKER WHO HAINT RED DA FUKIN STANDARD ARENT U? UR DA REASON DEANIS RICKY'S DEAD.
Name:
Anonymous2013-04-10 10:14
DEANIS RICKY
That one that died together with grandmaster Steve Jobs?
Name:
Lambda A. Calculus2013-04-10 10:25
>>58
HE DIDNT DIE WIT STEVE JOBS, HE DIED RITE DER IN MY ARMS AS HE DID HIMSELF IN WIT A PISTOL TWO DAYS AFTER DA FINAL DRAFT REVIEW OF C11. DAT FINAL DRAFT IS EXACTLY WAT LED HIM TO SUICIDE. DEM GREEDY, MENACING HYENAS AT ISO WHO RUINED DA LANGUAGE DEANIS RICKY LOVED. DEY'RE DA REASON DEANIS RICKY DID HIMSELF IN, DEY'RE WHAT MADE HIM DEPRESSED OVER DA YEARS, AND DEY'RE DA GREEDY FATCATS WHO TURNED C FROM DA LANGUAGE OF KINGS TO A STEAMING PILE OF SHIT WITH DER GOOTCHY rsize_t TYPE, DER WUNDERFUL THREAD LIBRARY, AND ALL DAT OTHER BULLSHIT. CAN YA BLAME RICKY FOR DOIN' HIMSELF IN WHEN THE WORLD'S FILLED WITH DEEZ FILTHY SCOUNDRELS WHO WILL TAKE A BRIGHT, BEAUTIFUL FLOWER LIKE C89 AND TURN IT INTO A PERVERTED STEAMING PILE OF SHIT LIKE C11?
WHY DA FUCK DO YOU CUNTS THINK THERE WAS NO K&R3 TO COVER C99? WHEN DEANIS RICKY SAW C99 HE SPENT DA WHOLE NIGHT THROWIN' UP. C11 WAS DA LAST FUCKIN STRAW. DA NAIL IN DA FUCKIN COFFIN. I KNOW THIS BECAUSE I WAS DER. I'M DA GUY WHO WROTE MOST OF DA string.h FUNCTIONS DAT YOU SEE NOW IN DA STANDARD C LIBRARY. I KNOWN RICKY SINCE BEFORE C WAS EVEN STANDARDISED. HELL, I KNEW HIM SINCE BEFORE HE EVEN PLANNED ON DESIGNING C.
Name:
592013-04-10 10:32
I'M DA GUY WHO WROTE MOST OF DA string.h FUNCTIONS DAT YOU SEE NOW IN DA STANDARD C LIBRARY.
N IF YA DONT FUCKIN BELIEVE ME, ASK ME A QUESTION BOUT ANY ABBREVIATED NAMES USED IN DA C LANGUAGE OR STANDARD C LIBRARY AND I'LL TELL YA EXACTLY WHAT DEY MEAN. DOSE DEFINITIONS HAVE BEEN LOST OVER DA YEARS AND I'M ONE OF DA ONLY PEOPLE LEFT WHO REMEMBER EM.
>>64
I'M LAMBDA ARTHUR CALCULUS. DAS WHO I AM. I KNOWN DAT SINCE DAY #1. HOW BOUT U? HUH? U PROBABLY THINK UR ANONYMOUS OR SUMFIN CUZ U DONT KNO WHO U R.
>>66
CHARACTER ALLOCATE, STRING POINTER BREAK, STRING COMPLEMENT SPAN, SET VARIABLE BUFFER. DEM ISO FATCATS WUDNT EVEN PUT DAT IN DA FUCKIN STANDARD WUD DEY?
calloc DONT CLEAR SHIT AND calloc DONT COUNT SHIT. SETS DAT SHIT TO 0. CANT USE IT FOR NULL POINTERS, CAN'T USE IT FOR ZERO FLOATING POINT VALUES, FUCKIN USELESS FOR EVERYTHING ASIDE FROM INTEGER TYPES. TAKE A LOOK AT STRNCPY, BUDDY. ZERO! ZERO! ZERO! PADS THAT SHIT WITH ZERO. AND DATS WHAT DEY DID WITH FILENAMES, DEY FUCKIN calloc'ed EM WHEN DEY NEEDED A VARIABLE-LENGTH LIST OF EM. DATS HOW DEY FIRST USED IT AND I KNOW THTIS COS I WAS THERE. THOSE FAT CATS ON comp.lang.c DON'T WANT YOU TO KNOW ABOUT strncpy. THEY THINK IT'S BAAAAAD PRACTICE. THAT'S WHY THEY CREATED THAT BULLSHIT NAME "clear alloc". I LAUGH AT DAT SHIT. I KNOW HOW TO USE strncpy AND I KNOW HOW TO USE strncmp! I FUCKIN WROTE THOSE FUNCTIONS.
"string character span" - YEA SURE. WHY DA FUCK WOULD I HAVE CALLED IT "string character span" WHEN IT DOES DA FUCKIN OPPOSITE OF "string span"? THEY BOTH ACCEPT TWO FUCKING STRINGS FOR FUCKS SAKE. COMMON SENSE ALONE'LL TELL YA DATS A LOAD OF SHIT. I KNEW WHAT I WAS DOIN DEN AND I KNO WAT I'M DOIN NOW. WUD I HAVE GIVEN strcspn SUCH A STUPID MEANINGLESS NAME? FUK NO.
NEXT!
Name:
Anonymous2013-04-11 2:56
OH YEAH, AND JUST A NOTE FOR ALL YOU FUCKS WHO THINK DA SECOND PARAMETER OF calloc WAS USED TO SPECIFY THE SIZE OF A TYPE, DIS IS HOW IT WAS USED:
calloc(desired_list_size, filename_length);
CHARACTER ALLOC! NO FUCKING SHIT. THEY HAD FIXED FILENAMES BACK THEN.
I just come back from time to time to check this shit. Wassup, no more comments, you tired sir Lambda Fucking Calculus? Come on dude, a guy like you with soooooo many medals cannot give up so easy. Bring it on, dude! I want some serious fight, the internets is getting so damn boring these days! Here is more stuff for you to get cocky: http://wololo.net/talk/viewtopic.php?f=37&t=10045 I'm sure you'll fucking love it. Hope to hear from you soon, bitch!
Name:
L. A. Calculus!!wKyoNUUHDOmjW7I2013-10-05 5:47
>>103
I'M WAITIN FOR U TO START ACTIN LIKE A FUCKIN JACKASS. GET TO IT, RETOID. I AIN'T GONNA GO LOOKING FOR UR SHIT. U BRING UR SHIT INTO MY THRED AND I MAKE U EAT IT. DAT'S DA WAY IT WORKS, AND DAT'S HOW IT'S GONNA KEEP WORKIN.
I THINK IT'S TIME U SHOVED AN ASSEMBLER UP UR ASS, STACK BOI.
Name:
L. A. Calculus!!wKyoNUUHDOmjW7I2013-10-05 6:02
AHAHAHAHA. ONE FUCKIN GLIMPSE AT UR SHITTY TUTORIAL AND I CUDN'T FUCKIN RESIST.
HE CALLS DIS SHIT 'Advanced C (II)':
Ok so now that we know variables are stored into the stack
AHAHAHAHAA
WAT ABOUT 'VARIABLES' WITH STATIC STORAGE DURATION, YA FUCKIN RETOID? EVER THINK ABOUT DEM? LMFAO
WAT ABOUT DA 'VARIABLES' WITH AUTOMATIC STORAGE DURATION DAT GET OPTIMISED UP AND R STORED ONLY IN REGISTERS? HAHAHAHAHAHA
YAINT RED DA STANDARD, UR A FAILURE AT BEING A STACK BOI, AND WAT UR IDEA OF 'ADVANCED C PROGRAMMING' IS JUST POKING AROUND MEMORY LIKE A FUCKIN MONKEY.
SOME DAY I'LL SHOVE A STACK UP UR ASS AND ALLOCATE A LOCAL VARIABLE AS WIDE AS UR MUM'S PUSSY SO IT OVERFLOWS INTO UR FUCKING BRAIN, AND DEN I'LL memcpy DA FUCKIN STANDARD TO IT SO U BECOME A DECENT FUCKIN PROGRAMMER FOR ONCE.
C/C++ is just an annoying language to fight against for the simplest task...
AHAHAHHAA. DESPITE A COMPLETE LACK OF INSIGHT, U'VE STUMBLED UPON A PERFECT ILLUSTRATION FOR A DAY IN DA LIFE OF UR TYPICAL STACK BOI.
Name:
Anonymous2013-10-05 6:59
>le pedophile standard
Real programmers don't need to be forced to work within a set of constraints. Real programmers use everything at their disposal to make the most interesting code possible. I think that it's extraordinarily important that we in computer science keep fun in computing. When it started out, it was an awful lot of fun. Of course, the paying customers got shafted every now and then, and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful, error-free perfect use of these machines. I don't think we are. I think we're responsible for stretching them, setting them off in new directions, and keeping fun in the house. I hope the field of computer science never loses its sense of fun. Above all, I hope we don't become missionaries. Don't feel as if you're Bible salesmen. The world has too many of those already. What you know about computing other people will learn. Don't feel as if the key to successful computing is only in your hands. What's in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.
Name:
Anonymous2013-10-05 10:04
progriders.org
Name:
L. A. Calculus!!wKyoNUUHDOmjW7I2013-10-05 18:08
>>106
GO WORK ON UR SPARROW OS PIECE OF SHIT, TERRY. I THINK IT'S TIME FOR U TO EITHER START TAKING UR FUCKIN MEDS, OR GET KIDNAPPED AND TAKEN TO A STRANGE PLACE THEN THROWN IN A FUCKIN CESSPOOL AND REBUILT FROM THERE. EITHER WAY, GET DA FUCK OUT OF MY THRED, YA RETOID.
UR OPERATING SYSTEM'S A HUNK OF CRAP. YAINT A REAL PROGRAMMER, UR JUST A FUCKIN FAIRY BOI RETOID.
DO ANY OF UR FUTURE MAINTAINERS A FAVOUR AND STAY DA FUCK AWAY FROM STANDARDISED PROGRAMMING LANGUAGES.
Name:
m0skit02014-01-02 10:44
>>106
You seriously arguing with a lambda troll? ROFL! Watch out, he might closure on you.
>>104
I AIN'T GONNA GO LOOKING FOR UR SHIT >>105
ONE FUCKIN GLIMPSE AT UR SHITTY TUTORIAL
So you ate my shit, huh bitch? I'm sure it tasted fine for you, since you probably have that for lunch, LMFAO! Go get a life SIR!
Name:
Anonymous2014-01-02 11:35
>>109
me I have not looked at your tuto not a fuckin glimpse
because its shit
and I know its shit beacause your a loser
Name:
Anonymous2014-01-04 1:32
d-bus
Name:
L. A. Calculus!!wKyoNUUHDOmjW7I2014-01-09 23:21
>>109
LERN TO REED YA FUKIN RETOID. LERN TO QUOTE TEXT TOO. I DON'T EET UR SHIT, I THROW IT BAK IN UR FACE. KNO WHY? COS I'VE ACTUALLY RED DA FUKIN STANDARD.
AND WEN U LEARN TO REED, GO REED KERNYAN N RICKY 2, REED DA FUKIN STANDARD, DEN GET DA GOOD MIND TO DELETE UR SHITTY TUTORIAL BEFORE U BREED MORE SHIT-GOBBLING STAK BOIS.
I CUM BAK FROM HAWAII AND I GOTTA DEAL WITH ALL DESE NINCOMPOOPZ. NOT TO MENTION DA FUKIN CAPTCHAZ