My First Hello, World in C. Very proud!

  Рет қаралды 70,263

Tsoding Daily

Tsoding Daily

2 жыл бұрын

Sorry for no camera. I moved to a different apartment recently and couldn't find it.
References:
- Type punning: en.wikipedia.org/wiki/Type_pu...
- The Shitpost: / 1433170025796472836
- The Source Code: gist.github.com/rexim/326dceb...

Пікірлер: 117
@TsodingDaily
@TsodingDaily 2 жыл бұрын
I lied. This was not my first Hello World. I'm really sorry.
@yb1829
@yb1829 2 жыл бұрын
hOw CoUlD yOu ????? 😮😮😮
@upobir
@upobir 2 жыл бұрын
!unsub
@ribosomerocker
@ribosomerocker 2 жыл бұрын
I thought we were friends...
@SquidBeats
@SquidBeats 2 жыл бұрын
Liars go to hell
@88farrel
@88farrel 2 жыл бұрын
I hope you have long fulfilling life
@MrInsanepotato
@MrInsanepotato 2 жыл бұрын
The technique is pretty clever and interesting but I'm just wondering how someone can get this gud at using emacs
@basscass710
@basscass710 2 жыл бұрын
I'm getting better but the trick with emacs is that you just get used to the inconvenient keyboard macros and bindings. Like if i want to delete the line below me I would ctrl-b ctrl-a ctrl-space del. I didnt have to think about it at all, but to save time i had to stop and think about my binding everytime I wanted to do that. So I opted to hurt my muscles and use ctrl-l b 1 del :) I'm sure there is even a better way cause that saves that line to clipboard lol
@j.r.r.tolkien8724
@j.r.r.tolkien8724 2 жыл бұрын
@@basscass710 WOW this sounds terrible I'd rather use vscode and spend my time learning something more useful like programming
@Phytolizer
@Phytolizer 2 жыл бұрын
@@j.r.r.tolkien8724 The thing is, you don't think about the keybinds when you're this efficient at an editor. You just think "I want to make X edit" and your fingers do the rest. I am able to do the same thing with Vim (j d d k).
@j.r.r.tolkien8724
@j.r.r.tolkien8724 2 жыл бұрын
@@Phytolizer I know and I do use a lot of keybindings and shortcuts myself but within a modern and easy to use text editor so whatever advantage the other non-intuitive and old ones have to offer I just don't think it's worth learning
@basscass710
@basscass710 2 жыл бұрын
@@j.r.r.tolkien8724 I learned to make it easy, easier than vscode. Unlike vscode, I don't need a blackbox web framework to take up two weeks of my time to extend. It takes me an afternoon if not a couple of hours with lisp. Things take time to get good at and emacs is hard to master, I want to master it. You can say the same thing for gnu/linux or literally any hobby or skill, "WOW sounds terrible i'd rather use Windows than gnu+linux and spend my time learning something more useful like gaming" "WOW sounds terrible I'd rather use and ikea desk than make one and spend my time learning to draw desks lol". That's a loser mind set and you don't even know how to program lol
@Ak4n0
@Ak4n0 2 жыл бұрын
Don't worry, all globals are initialized to zero for default, unlike locals. And good job, it's a good video :D
@BradenBest
@BradenBest Жыл бұрын
the version shown in the video makes perfect sense since it ANDs with 0xf (1111) instead of 0377 (11111111) and thus the right shifts don't go out of control. What threw me trying to decipher this is that the 0377 version works. _Why_ does it work? Right shift by amounts larger than the type are undefined. The first iteration yields a shift amount of 0x208 (it's over 500), which is way larger than 64. Case in point, 0x1 >> 200 gives some giant garbage number rather than any hex number with a single 1, 2, 4, or 8 digit. I actually paused the video at 0:48 once I noticed the 0xF in there and made a second attempt at deciphering it and succeeded. My best guess for the 0377 version is that the compiler is wrapping the shift amount mod 64, since 0x208 % 64 yields 8 and 0x2a0 % 64 yields 32. I have a whole table I wrote up in my text editor but pasting it here would be impossible cause youtube would fuck up the heavily whitespaced formatting if I did. That said I ended up with this, which reads as "Hello World" to me 0 726F6C6564574820 >> 8 726F6C65645748 1 726F6C6564574820 >> 32 726F6C65 2 726F6C6564574820 >> 40 726F6C 3 726F6C6564574820 >> 40 726F6C 4 726F6C6564574820 >> 48 726F 5 726F6C6564574820 >> 0 726F6C6564574820 6 726F6C6564574820 >> 16 726F6C656457 7 726F6C6564574820 >> 48 726F 8 726F6C6564574820 >> 56 72 9 726F6C6564574820 >> 40 726F6C A 726F6C6564574820 >> 24 726F6C6564 (told you YT would fuck it up, they're supposed to be right-justified) Anyway, I'll watch the video now.
@Red-di7zb
@Red-di7zb 2 жыл бұрын
Да, это жестко.
@_general_error
@_general_error 2 жыл бұрын
Nitpick: You can iterate until x = 0 in the case when your encoded string doesn't have one or more characters at the end, which are the first (0th) in your character table. But it's fine for a Hello World specifically. Also what you tweeted has obviously the index table encoded in 4-bit chunks, which still fits into 64 bits - the index tables are different.
@tonyli1212
@tonyli1212 2 жыл бұрын
After watching this video, I just realized that I accidentally watched this half hour long video
@mikkmikimikk123
@mikkmikimikk123 2 жыл бұрын
You can also fit more characters in the table by reducing the size of each character. If it's ASCII-only, then you can just use 7 bits per character, which bumps you up from 8 to 9 characters. If 26 alphabetic characters is enough and you add 65/0x41/0101 to that index, you can even bump it up to 5 bits per character / 12 characters.
@JinskuKripta
@JinskuKripta 2 жыл бұрын
Yeah we know, but the video is 30min long, if he had applied what you said the video would be more interesting but much more fucking longer
@michelezenoni1137
@michelezenoni1137 2 жыл бұрын
I think that in the Twitter example the 4 bits shift and the & with 0377 still works because u've just considered (I guess) the indices made of 4 bits each (instead of 3 ) so 11*4 = 44 bits for all indexes + 4 bits for '\0' which still fits in a 64bits int, that's why the hexadecimal number (dx) is made of 12 digits (48 bits). I haven't fully understood the 0377 mask even with the 4 bits for an index, you should be able to remove it and it should work anyway; if u want to use a mask for 4 bits indices is & 15 (like & 7 for the 3 bits). Tsoding hid it so well that he couldn't remind the explanation himself, goal achieved! (And btw don't take this explanation too seriously, I wrote it just because I was curious) :)
@superhawk6105
@superhawk6105 2 жыл бұрын
Perhaps 0377 is interpreted as octal? If so, that’s 255 decimal, or 0xFF hex…
@michelezenoni1137
@michelezenoni1137 2 жыл бұрын
@@superhawk6105 yeah, I've just checked and you're right...I didn't know that representation of octal numbers in C, thanks! The explanation I gave should be valid anyway but now I know something new :)
@Henry-sv3wv
@Henry-sv3wv 2 жыл бұрын
@@superhawk6105 yea, the leading zero means octal, so 0377 is decimal 255 is 0xFF
@simonfarre4907
@simonfarre4907 2 жыл бұрын
Dude he copied it off of someone else. Otherwise he would have known what any, first semester programmer would know, that 0377 is 0xff in octal base.
@michelezenoni1137
@michelezenoni1137 2 жыл бұрын
@@simonfarre4907 I didn't copy anyone, I missed that when I wrote the comment hahaha
@ThatBastardOverThere
@ThatBastardOverThere 2 жыл бұрын
Haha, I wonder if you could even make it so that all of the extra numbers like the 3s and the 7 are themselves obtained via shifting the index. Of course, this would start to depend on your message containing index 3 and 7...
@MCLooyverse
@MCLooyverse 2 жыл бұрын
The way I print a list is either to emit "\b\b]" at the end, or I create a string, which can be easily modified, then printed in one go.
@mxthevs
@mxthevs 2 жыл бұрын
28:09 nice
@SquidBeats
@SquidBeats 2 жыл бұрын
Jesus Christ is God and is the only way. Hell is real whether you believe it or not
@monochromeart7311
@monochromeart7311 2 жыл бұрын
@@SquidBeats I rented a good apartment in hell, so I can confirm.
@Gahlfe123
@Gahlfe123 Жыл бұрын
this was great, a lot of neat patterns
@MCLooyverse
@MCLooyverse 2 жыл бұрын
I would have had the indecies be 4 bit values, just because working with nybbles is (usually) significantly easier that with triples (although, that's a very good reason *not* to use nybbles in this case). I would guess that that's what you actually did the first time, which is why that's how you explained it, and why that's what's in your original code (notice also that the value of `dx` *is* different in the original). Also, in the original, you're missing the single-byte mask...but it works, because the value is being implicitly cast to a single byte anyway.
@xetera
@xetera 2 жыл бұрын
Thankfully I watched the "What is IO Monad" video so I can understand that line of code with >>=
@MCLooyverse
@MCLooyverse 2 жыл бұрын
Ha! I've wondered about overloading operator>>= to be bind for some class(es) in C++.
@user-cr9ix2mg5u
@user-cr9ix2mg5u 2 жыл бұрын
Great vid. What font are you using btw?
@user-cr9ix2mg5u
@user-cr9ix2mg5u 2 жыл бұрын
Looks like its Iosevka (went through some older vids). However theres like 100 versions of it haha, which one is yours specifically if you remember?
@antiMatterDynamit
@antiMatterDynamit 2 жыл бұрын
the indexes could fit in 32 bits if you make sure your last index references one of the first 4 characters
@whythosenames
@whythosenames 2 жыл бұрын
If you would put one more extra zero byte to the index, you could change the & 7 to & 56 to omit the >= 3 to /= 8 and & 0xFF to * 256 to make things shorter. And im not sure abort that one, but can one use long long on all platforms to get rid of the second include?
@vojtechsejkora1554
@vojtechsejkora1554 2 жыл бұрын
If I remind correctly from school curse about C and memory, only what you have garanteed is this eneguality for type size int
@whythosenames
@whythosenames 2 жыл бұрын
@@vojtechsejkora1554 ok that char thing with 9 bits is very weird. I also thought i heard somewhere that char >= 8 bits, short >= 16 bits, int >= 32 bits and long long >= 64 bits but i dont know for sure
@AGENTX506
@AGENTX506 2 жыл бұрын
​@@whythosenames Not quite true, C began in the 16-bit era, so guaranteeing the default int type to be >= 32 bits would be slow and wasteful. Older processor architectures, and even today some microcontrollers like the AVR series, have 16-bit shorts, 16-bit ints (yes they're both 16-bit), 32-bit longs, etc.. The AVR compiler even has both floats and doubles being the same 32 bits in size, since the C spec doesn't specify their sizes at all.
@TheMuffinMan
@TheMuffinMan 2 жыл бұрын
The fastest hello world known to mankind.
@Makotom
@Makotom 2 жыл бұрын
You can make more videos of obfuscation?
@tenj00
@tenj00 2 жыл бұрын
This reminds me of ArnoldC. The best programming language out there! Get to the Chopper!
@IT_Shkolnik
@IT_Shkolnik 2 жыл бұрын
At 13:45 you wrote a «sizeof(idx[0])». I have a question: If size of one element in array equals size of type of an array «sizeof(size_t)» why do you getting size by one element? Or these are different?
@mikkmikimikk123
@mikkmikimikk123 2 жыл бұрын
Using sizeof(arr)/sizeof(arr[0]) to get the size of the array in your code will help keep the code from breaking when you change the size or type of the array. If you write sizeof(size_t) instead, but then at some point decide that you want to store chars in arr to save space, then the size will be incorrect.
@IT_Shkolnik
@IT_Shkolnik 2 жыл бұрын
@@mikkmikimikk123 got it. Thanks
@neutron_stz8894
@neutron_stz8894 2 жыл бұрын
dont use that sizeof(idx[0]) instead use sizeof(size_t)
@proloycodes
@proloycodes 2 жыл бұрын
@@neutron_stz8894 ah yes, another intellectual who doesnt read replies.
@bruterasta
@bruterasta 6 ай бұрын
This is, more or less, how compilers are optimizing short strings. Just check O3 asm of hello world. Only the longer ones are ending up in .data.
@hoxorious
@hoxorious 2 жыл бұрын
Wow that was really cool
@Dom-zy1qy
@Dom-zy1qy 2 жыл бұрын
You vs the %99 leetcode submission
@alexandrohdez3982
@alexandrohdez3982 2 жыл бұрын
great video 👏👏👏
@ethaneshed7298
@ethaneshed7298 2 жыл бұрын
color theme? it looks really good
@hetsmiecht1029
@hetsmiecht1029 2 жыл бұрын
What's with your line numbers?
@TsodingDaily
@TsodingDaily 2 жыл бұрын
They are cursed
@magnusphilosophus506
@magnusphilosophus506 2 жыл бұрын
set number relativenumber in vim
@provakar5496
@provakar5496 2 жыл бұрын
Thank you for inspiring me to leave coding.
@Psykorr
@Psykorr 2 жыл бұрын
Cool!
@mastermati773
@mastermati773 2 жыл бұрын
8.8 GiB - Not great, not terrible.
@simonfarre4907
@simonfarre4907 2 жыл бұрын
I also love that he copied this straight off of someone else. Otherwise he would know that 0377 is octal for 255, or 0xff.
@TsodingDaily
@TsodingDaily 2 жыл бұрын
Who did I copy it from?
@monochromeart7311
@monochromeart7311 2 жыл бұрын
@@TsodingDaily from yourself in a different world line.
@johnjohnson6142
@johnjohnson6142 2 жыл бұрын
I take it you don’t know octal or hex Simon?
@simonfarre4907
@simonfarre4907 2 жыл бұрын
@@johnjohnson6142 what are you talking about? I just told you that 0377 is octal for 255 or 0xff.
@nested9301
@nested9301 2 жыл бұрын
whtat font u USING,?
@elatedbento
@elatedbento 2 жыл бұрын
I need the font used in the editor. My life depends on it.
@ayovb06
@ayovb06 2 жыл бұрын
I think its iosevka
@eduoliv
@eduoliv 2 жыл бұрын
22:18 Nazaré confusa kkkkk
@sournois90
@sournois90 6 ай бұрын
kkkkkkkkkkk
@EDToasty
@EDToasty Жыл бұрын
0377 == octal 377 == 255, so your mask was 8 bits wide?
@TowelPanel1852
@TowelPanel1852 2 жыл бұрын
Like the video but you should really get a pop filter
@mohnishkumar6847
@mohnishkumar6847 2 жыл бұрын
Name of ide?
@mohnishkumar6847
@mohnishkumar6847 2 жыл бұрын
Name of editor?
@xeriab
@xeriab 2 жыл бұрын
Emacs
@iliasalaur
@iliasalaur 2 жыл бұрын
Are you from Russia?
@leovaldez6280
@leovaldez6280 2 жыл бұрын
Hello and welcome to another zzzzzzzz
@alperkaya8919
@alperkaya8919 2 жыл бұрын
okey cool but you have wasted 30 munites just to print out hello world, you are really youtuber
@simonfarre4907
@simonfarre4907 2 жыл бұрын
My brain hurts every time he writes a for loop. He uses emacs, yet hasn't written an abbreviation or template for it. Then why use emacs?
@godnyx117
@godnyx117 2 жыл бұрын
I use Neovim and also don't use templates cause I don't like them and I actually like typing. Autocompletion is enough for some people
@Wraient
@Wraient 2 жыл бұрын
@@godnyx117 have you ever thought about visual studio code?
@godnyx117
@godnyx117 2 жыл бұрын
@@Wraient Yes I did
@GreatLich
@GreatLich 2 жыл бұрын
what the fuck man why? WHY? WHYYYYYYYY?
@pitust
@pitust 2 жыл бұрын
you use emacs therefore anything you did is invalid.
@radekwysocki7875
@radekwysocki7875 2 жыл бұрын
just do \t instead of %14s
@IsaacMak1102
@IsaacMak1102 2 жыл бұрын
homework: print hello world in c others: printf("hello world"); me:
@koksem
@koksem 2 жыл бұрын
python: print("Hello, World")
@evolade4044
@evolade4044 2 жыл бұрын
C: printf("Hello, World");
@koksem
@koksem 2 жыл бұрын
Assembly 64 bit: section .data msg db 10d,13d,"Hello World " l equ $-msg section .text global _start _start: mov rax,1 mov rdi,1 mov rsi,msg mov rdx,l syscall mov rax,60 mov rdi,0 syscall end:
@leosin5767
@leosin5767 2 жыл бұрын
for global array we can actually declare #define ARRAY_SIZE(X) (sizeof((X)) / sizeof((X)[0]))
@quatroctus5404
@quatroctus5404 2 жыл бұрын
I have decoded the code from the Twitter post. dx >>= 4: This version did use 4 bits instead of 3 bits for each "index". Which makes more sense because one could just (num & 0xF) to get the index. & 0377: This is octal for 0xFF or 255 in C. Why does the code bitwise and with 255 instead of 15 IDK. > above number: This performs the lookup in the character table. However this last step relies on undefined behavior in C. The first iteration works out to effectively (0x726F6C6564574820 >> 520). Logically bitshifting by greater than 64 should result in 0. However what actually happens at least on my hardware is it performs % bitlength or % 64 for a 64 bit int. 520 % 64 = 8. By rightshifting by 8 we grab the 2 entry in the char table. The char table is " HWdelor" which is the 'H' character.
@robbevandergucht3361
@robbevandergucht3361 2 жыл бұрын
I see you found the same behavior as myself. The reason for this is that the shift-left instruction on x86_64 only takes the first 5 bits into account. You can find this in the Intel instruction reference manual. I am not sure whether this is undefined behavior on the part of the C language. It is little known, but defined x86 behavior.
You don't need Generics in C
1:37:38
Tsoding Daily
Рет қаралды 56 М.
Coding Graphics in TempleOS is Too Easy
34:47
Tsoding Daily
Рет қаралды 165 М.
ПАРАЗИТОВ МНОГО, НО ОН ОДИН!❤❤❤
01:00
Chapitosiki
Рет қаралды 2,8 МЛН
100❤️ #shorts #construction #mizumayuuki
00:18
MY💝No War🤝
Рет қаралды 20 МЛН
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 105 МЛН
Will Ada Replace C/C++?
44:57
Tsoding
Рет қаралды 81 М.
Let's Talk About Functional Programming
1:47:07
Tsoding Daily
Рет қаралды 66 М.
I regret doing this...
1:20:07
Tsoding Daily
Рет қаралды 62 М.
Advanced C: The UB and optimizations that trick good programmers.
1:12:34
Eskil Steenberg
Рет қаралды 148 М.
How a simple highlight improves my communication at work
3:47
Rasmus Bergström
Рет қаралды 3 М.
Newton's Method in C
1:33:17
Tsoding Daily
Рет қаралды 19 М.
This Data Structure could be used for Autocomplete
1:54:31
Tsoding Daily
Рет қаралды 40 М.
The What, How, and Why of Void Pointers in C and C++?
13:12
Jacob Sorber
Рет қаралды 50 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 4,9 МЛН
ПРОБЛЕМА МЕХАНИЧЕСКИХ КЛАВИАТУР!🤬
0:59
Корнеич
Рет қаралды 3,8 МЛН
ПК с Авито за 3000р
0:58
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,9 МЛН
#miniphone
0:16
Miniphone
Рет қаралды 1,6 МЛН
Карточка Зарядка 📱 ( @ArshSoni )
0:23
EpicShortsRussia
Рет қаралды 662 М.
Main filter..
0:15
CikoYt
Рет қаралды 1,3 МЛН