On the topic of wishy washy subjective terms like "readability" and "maintainability" being used to justify painful practices with few actual benefits, I agree. I've seen "SOLID principles" spoken of like an undeniable natural law. Then you work on codebases where someone decided nearly every class needs a separate interface and implementation, and that you should have dependency injection everywhere, causing mysterious problems and extremely low developer productivity.
tcc is being developed. Recently they started working on riscv port, and it's pretty much fully working, other than assembler that is. That version just hasn't been release yet
Very fun to watch... we have been working on a compiler for clients so your adventures are appreciated! We decided to make everything -> in the end BTW.
Cool stuff. I recently did something similar by adding a `__TIMER__` macro to tcc with expands to a high resolution time. I used that to benchmark preprocessor expansion.
13:15 Here's a trick I like to use in cases like this - you already have TCC build with debuginfo, so you can do something like `strace -k -e write ./tcc ...` the -k switch will give you stack trace with func/file information.
they decided to add -> operator because original operators * and . precedence is broken by design, so you have to use parentheses in order to make it work: *struct_val.filed should be (*struct_val).field and after introduction of -> it became struct_val->field.
People are really complaining about """readability""" when ever other language uses the dot to access all of a class's elements regardless of its memory semantics.
Because new OSes require new compilers anyway, I'm thinking about hacking the tool chain for my OS in the same way as shown here. This would allow all programs written for the OS to use this feature!
C and C++ haven't been language compatible for aeons. They're still ABI compatible, and that's all anyone actually cares about. I can see no reason for this addition to C to change ABI compatibility with C++.
A series where you write a c like programming language that transpiles to c would be pretty interesting. Keeping the language as simple as possible and close to c but adding some convinience to it like order independent declarations, a better include system without the h files hell and implicit detection of multiple includes of the same file, the porth include system was pretty good and maybe a proper string datatype.
this has exactly been one of my ideas in the recent past, fix those little issues with c and make a better c, you can look into zig for something similar
Hey you! I love the way you are doing. It's so chill just to lie and see what you are doing, because it's so clear and understandable. Have a good day!
An interesting quirk of clang that helps with easily fixable cases like this is the flag “-fixit”. It will apply suggested fixes directly to source code, so even though it usually behaves well with simple cases like this, proceed with care! (And note that it must be passed in after the -Xclang flag)
I was about to say that you will confuse where pointers to struct are and where actuall structs are. But then I realized that C is statically typed language and compiler knows that you are trying to access field of the `struct *` and not a `struct`. So it is really possible to implement, yeah.
It is great to see the TCC "fix" I would have never thought about trying that and it is very informative to see. It was a good "reason" yet on editors like emacs or vim it seems a bit contrived. When pulling out code from main into functions, selecting them in these editors are a few keystrokes. I don't know emacs anymore for vim having the cursor on opening or closing squirely bracket v%s/foo\./foo->/g and no matter how many times "foo." is there it will be replaced. It is a blind muscle memory operation. At that point I'm code gardening anyway and renaming stuff a bit better, so I'm already doing substitutes. Sure the C compiler should have changed that and it probably has a historical reason why it is as it is. (v for visual selection. % jumps between bracket pairs. s/from/to/ substitution.)
I checked comments and it looks like nobody noticed that at about 01:00:00 he uses union (instead of struct) and therefore the program should print 70, not 69. Maybe he should have run a.out instead of main?
checkout a tool called tldr, for when you forget how a certain command is used, for instance `tldr ctags` (i use outfielder (zig) as client, but there's also tealdeer (rust) and tldr (python))
okay, this is really hot; the way you navigate w/ a window manager + vim. also appreciated the zoomed in terminal. one addition though: could you turn on screenkeys?
@@cooper2623 C is not a subset of C++, it's a different language. There is no "breaking compatibility with C++", because it's not even a thing in the first place. There is a subset of both languages compatible with each other, but a valid C++ is (obviously) not always a valid C AND a valid C is not always a valid C++. The obvious examples of what you can do in C that you cannot do in C++ are some implicit casts (eg. void* returned from malloc to a pointer to a different type) and designated initializers.
@@cooper2623 Oh yeah, good point. Iterators too. Although in order to override the unary * and ->, it requires that the left hand side be a class or struct, or a reference to such. It's not possible to override a raw pointer. If you are trying to refactor code that uses an iterator, you're going to be using -> in the first place, so moving it into an extracted function wouldn't change that. But refactoring in C++ usually means passing references, not pointers, so I guess the use case isn't really the same as it is in C. So I guess what I'm saying is, it might work, but it isn't really necessary, and you'd still have to type -> sometimes.
When using C I wondered about the same thing. I think it was justified with easier parser, but does that still apply for ‚C24‘. I wonder what kind of expressions could be a pointer and struct or something but can’t come up with any case.. (ptr++).a …?
47:50 - I feel the real reason is to ensure you know at a glance if the variable is a pointer or a struct when you're reading the code, which is not possible with autodereferencing. That said, that could also be the compiler's responsability as well nowadays.
I've always wondered about compatibility with small features like this. Most people are using pre-compiled binaries anyways, so if the programmer prefers it, why not?
About your keyboard: did you checked dmesg for messages that your keyboard was connected/disconnected? That way you will be certain where problem is: in hdwr or sftwr
It seems Tsoding doesn't like LSP, as Emacs has multiple very popular packages that are easy to setup for this exact purpose. `eglot` is (much) easier but less configurable, while `lsp-mode` lets you really get into the thick of it.
Arrows don't add any readability to code. It's just bussy-looking. You know type of `foo`, so why do you need to specify that `foo` is needed to be accessed via `(*foo).` or `foo->` anyway?
Да все также будет работать - это ответ на твит. Т.к. кода, который использует этот хак, нет; И ничего не сломается по этой же причине. За исключением нового, кода который Вы напишите. Поэтому, что вы тут пытались сделать, не понятно? Разве что поковырять чутка tcc. ))
These showed up in the original programming C book and have been used in example code ever since. FUBAR, I believe is an informal military term in the us. Not sure if it is related.
Yes, I'm currently in Russia, specifically Siberia. I completely understand if this is defining factor for you to decide whether to watch my content or not, but keep in mind that I do not earn any money from it.
@@TsodingDaily nothing's wrong man. I'm also from Russia and also from Siberia. I just wanted to make sure my thoughts are right. Also it's nice to know there're such good hackers living in Russia
The computer understands that, what tsoding did is not make them the same, he just made an auto dereference via the "." when needed on struct pointers withotu the "->". Not always. semantically it is different, however functionally it remains the same.
Imagining add 2 lines of code in a language that is 50 years old and having such a nice feature!!! kudos!
On the topic of wishy washy subjective terms like "readability" and "maintainability" being used to justify painful practices with few actual benefits, I agree. I've seen "SOLID principles" spoken of like an undeniable natural law. Then you work on codebases where someone decided nearly every class needs a separate interface and implementation, and that you should have dependency injection everywhere, causing mysterious problems and extremely low developer productivity.
It is OOP, everything that you will made will be bad, because the underlining language is fundamentally flawed.
tcc is being developed. Recently they started working on riscv port, and it's pretty much fully working, other than assembler that is. That version just hasn't been release yet
I'm loving the consistent uploads!
Very fun to watch... we have been working on a compiler for clients so your adventures are appreciated! We decided to make everything -> in the end BTW.
Cool stuff. I recently did something similar by adding a `__TIMER__` macro to tcc with expands to a high resolution time. I used that to benchmark preprocessor expansion.
Thanks for making such awesome videos. Always get to learn something new or gain new perspective on things from them.
I just love that C compiler content :D
Even though I no way near that level of expertise, thank you tsoding :)
13:15 Here's a trick I like to use in cases like this - you already have TCC build with debuginfo, so you can do something like `strace -k -e write ./tcc ...` the -k switch will give you stack trace with func/file information.
Just add a warning saying this isn't in-spec and won't work with older compliers, and then there is no downside to this feature.
they decided to add -> operator because original operators * and . precedence is broken by design, so you have to use parentheses in order to make it work: *struct_val.filed should be (*struct_val).field and after introduction of -> it became struct_val->field.
People are really complaining about """readability""" when ever other language uses the dot to access all of a class's elements regardless of its memory semantics.
Correct, It can’t be readability since c uses . anyway
bruh this guy has a super computer working in sync with his brain how does he know so much stuff
Because new OSes require new compilers anyway, I'm thinking about hacking the tool chain for my OS in the same way as shown here. This would allow all programs written for the OS to use this feature!
C and C++ haven't been language compatible for aeons. They're still ABI compatible, and that's all anyone actually cares about. I can see no reason for this addition to C to change ABI compatibility with C++.
I was so hoping you would choose tcc and he did. Such a relief
A series where you write a c like programming language that transpiles to c would be pretty interesting. Keeping the language as simple as possible and close to c but adding some convinience to it like order independent declarations, a better include system without the h files hell and implicit detection of multiple includes of the same file, the porth include system was pretty good and maybe a proper string datatype.
this has exactly been one of my ideas in the recent past, fix those little issues with c and make a better c, you can look into zig for something similar
Hey you! I love the way you are doing. It's so chill just to lie and see what you are doing, because it's so clear and understandable. Have a good day!
An interesting quirk of clang that helps with easily fixable cases like this is the flag “-fixit”. It will apply suggested fixes directly to source code, so even though it usually behaves well with simple cases like this, proceed with care! (And note that it must be passed in after the -Xclang flag)
Curious to know if everything would still work if you search and replace all the arrows with dots in the TCC compiler
Really nice stream! Thanks a lot!
I was about to say that you will confuse where pointers to struct are and where actuall structs are. But then I realized that C is statically typed language and compiler knows that you are trying to access field of the `struct *` and not a `struct`. So it is really possible to implement, yeah.
This patch is amazing
I could watch 50 episodes of making c better like this
It is great to see the TCC "fix" I would have never thought about trying that and it is very informative to see. It was a good "reason" yet on editors like emacs or vim it seems a bit contrived. When pulling out code from main into functions, selecting them in these editors are a few keystrokes. I don't know emacs anymore for vim having the cursor on opening or closing squirely bracket v%s/foo\./foo->/g and no matter how many times "foo." is there it will be replaced. It is a blind muscle memory operation. At that point I'm code gardening anyway and renaming stuff a bit better, so I'm already doing substitutes.
Sure the C compiler should have changed that and it probably has a historical reason why it is as it is.
(v for visual selection. % jumps between bracket pairs. s/from/to/ substitution.)
Goddamn this was so satisfying
33:47 i actually noticed like ten minutes ago and it was satisfying when he got back into that
Original and engaging content, thanks.
Some people argue that the arrow is being explicit about the indirection, while auto deref hides that fact
Yeah, I agree. Some people do like to argue about useless things.
@@TsodingDaily totally agree, and i forgot to add that i am not, i actually really like auto deref in other languages and think it should be in C
I checked comments and it looks like nobody noticed that at about 01:00:00 he uses union (instead of struct) and therefore the program should print 70, not 69. Maybe he should have run a.out instead of main?
C23 in process.
checkout a tool called tldr, for when you forget how a certain command is used, for instance `tldr ctags`
(i use outfielder (zig) as client, but there's also tealdeer (rust) and tldr (python))
+1 for tldr, it's great to avoid searching through man pages or --help output.
Can new entries be added or are they all hard-coded?
It would be cool to be able to give docstrings to any shell command...
okay, this is really hot; the way you navigate w/ a window manager + vim.
also appreciated the zoomed in terminal.
one addition though: could you turn on screenkeys?
oh that's Emacs. was getting confused about how those buffers were working
17:00: LOL, You crazy Sosing!
I need this in my life. But why would it break C++?
I don't know. Somebody in the chat said that.
Tbh, I feel like at this point any change can break C++.
It would break C++ because you can override the -> operator. std Smart pointers do that, for example.
@@cooper2623 C is not a subset of C++, it's a different language. There is no "breaking compatibility with C++", because it's not even a thing in the first place. There is a subset of both languages compatible with each other, but a valid C++ is (obviously) not always a valid C AND a valid C is not always a valid C++. The obvious examples of what you can do in C that you cannot do in C++ are some implicit casts (eg. void* returned from malloc to a pointer to a different type) and designated initializers.
@@cooper2623 Oh yeah, good point. Iterators too. Although in order to override the unary * and ->, it requires that the left hand side be a class or struct, or a reference to such. It's not possible to override a raw pointer. If you are trying to refactor code that uses an iterator, you're going to be using -> in the first place, so moving it into an extracted function wouldn't change that. But refactoring in C++ usually means passing references, not pointers, so I guess the use case isn't really the same as it is in C. So I guess what I'm saying is, it might work, but it isn't really necessary, and you'd still have to type -> sometimes.
dang this guy is good
Next up Tsoding adds Rust like mutability in C
I thought ai forgot how unions worked until you realized the command was wrong. Oh I doubt myself too much.
58:58 small tip, you could have defined the macro SDL_audio_h_ (the one in the ifndef wrapper) to not include the audio header
When using C I wondered about the same thing. I think it was justified with easier parser, but does that still apply for ‚C24‘. I wonder what kind of expressions could be a pointer and struct or something but can’t come up with any case.. (ptr++).a …?
"struct, union or ur mom" c:
47:50 - I feel the real reason is to ensure you know at a glance if the variable is a pointer or a struct when you're reading the code, which is not possible with autodereferencing. That said, that could also be the compiler's responsability as well nowadays.
Good work, really awesome.
I've always wondered about compatibility with small features like this. Most people are using pre-compiled binaries anyways, so if the programmer prefers it, why not?
this makes me wonder why they added the arrow...
About your keyboard: did you checked dmesg for messages that your keyboard was connected/disconnected? That way you will be certain where problem is: in hdwr or sftwr
Just a second before you started typing "ur mom" at 17:00 I said the exact same thing :D that was hilarious to me only unfortunately. Great job here!
1:10:40 screams YOUR DEFINES
You come up with the most interesting ways to tinker when programming. Any chance you'd explore writing an implementation of Refal?
Maybe consider installing an LSP in emacs, have no idea how, i use nvim. But you could have just called `go to definition` from the LSP on `next()`
It seems Tsoding doesn't like LSP, as Emacs has multiple very popular packages that are easy to setup for this exact purpose. `eglot` is (much) easier but less configurable, while `lsp-mode` lets you really get into the thick of it.
58:00 strange! I'm using TCC & SDL2 without this problem under windows.
you WHAT?
thanks to vim, this video is longer
Wait why do people hate -> so much?
Arrows don't add any readability to code. It's just bussy-looking. You know type of `foo`, so why do you need to specify that `foo` is needed to be accessed via `(*foo).` or `foo->` anyway?
7:29 since c++ is a superset of c, the popularity of c doesn't actually indicate the quality of c++ very well.
How old are you?
Да все также будет работать - это ответ на твит. Т.к. кода, который использует этот хак, нет; И ничего не сломается по этой же причине. За исключением нового, кода который Вы напишите. Поэтому, что вы тут пытались сделать, не понятно? Разве что поковырять чутка tcc. ))
What is Foo and bar ?
Names that are used for simple examples, like n is used for integers. It's an American thing, I never understood where they came from either.
These showed up in the original programming C book and have been used in example code ever since. FUBAR, I believe is an informal military term in the us. Not sure if it is related.
Are you from Russia? Your accent sound as Russian accent and your account was registered in Russia
Yes, I'm currently in Russia, specifically Siberia. I completely understand if this is defining factor for you to decide whether to watch my content or not, but keep in mind that I do not earn any money from it.
@@TsodingDaily nothing's wrong man. I'm also from Russia and also from Siberia. I just wanted to make sure my thoughts are right. Also it's nice to know there're such good hackers living in Russia
Понятно!
dicord server link ?
go on his twitch... or you know wait for someone to give it to you: discord.gg/KehewYS
go to his twitch channel
yoo
If we use ' .' As '->' then how the pc can understand what is normal object and what is in pointer mode in order to treat it differently
If the compiler says that you don't use the correct one then it already knows what is a pointer or not.
The computer understands that, what tsoding did is not make them the same, he just made an auto dereference via the "." when needed on struct pointers withotu the "->". Not always. semantically it is different, however functionally it remains the same.
Cause pointer declarations are explicit ??? You always know if somet is a value or a pointer
The computer (compiler) knows that from the type of the value that can be deduced for example from its declaration.
You declare what every symbol is (eg. int* myIntPointer)
Why not create simple app for example MP3 player or painting program thinks like this
He does what he is interested in! That's what keeps the videos interesting, IMO.
hey, does the original way of dereferencing structs work? for example *foo.value
Why wouldn't it work?
@@TsodingDaily just curious, but yeah, it should work. (and too lazy to check by myself :) )