Why is C Compiler So Smart?

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Why is the C compiler so smart?
Because people have been building on it for 5 literal decades

ShotgunLlama
Автор

there is '-ffreestanding' which does exactly what you say about assuming there is no stdlib, but will still do builtin optimizations that may no call a std libarary function.

wChris_
Автор

I heard the GCC is so smart if you try to give it the source of Clang to compile it'll spit out a link error for job security.

bluesquare
Автор

The fun part is that if you overwrite memset with a different functionality it will still call memset and call your memset.

oj
Автор

Try allocate big chunk of stack memory and only use first element, the compiler simply create stack memory as big as a single element, clever!

KangJangkrik
Автор

I find clang and gcc normally spot the same tricks... but clang will be 100x more aggressive in applying them.

This is especially noticeable with how the two compilers unroll loops. Clang will straight out remove all jmp instructions and replace it with 100 avx instructions whereas gcc will do the same thing but in batches of 10 between jmp instructions. Honestly LLVM is so aggressive in optimisations it amazes me a lot of the time.

I don't know what it's like now but the only thing gcc used to be better at was spotting how to replace long complicated code with bithackery.

hitlerssecondcoming
Автор

There was this one time a student was running into a seg fault with GCC and it didn't happen when compiling with CLANG.

He wrote something like "if (aux->value > 0 && aux != NULL)". Basically he tried to access the pointer before checking if it is NULL, which sometimes lead to the segfault.

All he had to do to stop the segfault was check if it is null first ("if (aux != NULL && aux->value > 0)". His code ran correctly in both situations when compiling with CLANG, while with GCC only the latter would work. I found this quite interesting.

ludo
Автор

I really appreciate the large text size and clear resolution. Makes following along so much easier

drygordspellweaver
Автор

Is no one gonna mention how at the bottom it says "Porn Folder: 7.6 GiB (too smol PepeHands)" ???
That's a lot of space, dude lol

frozenBird
Автор

i don’t think C compiler recognizes intent, I think it recognizes idioms

feedmewifi_
Автор

it's so smart it can't check if u include stl to the project xd

adamkurek
Автор

We should rewrite the C compiler in Rust!!!

thestemgamer
Автор

Dude, your content is so interesting! You have a very good way with words, which is additively impressive considering you're Russian too

Axlefublr
Автор

I'm gonna bet on horses, use compiler somehow to optimize my desired outcome.

tommytomtomtomestini
Автор

Seems like an opt code pattern. no wonder. compiler engineers did tons of trial-and-error to optimize code. that's it. looks like a quick magic, but it just a pattern to optimize.

playloud
Автор

Try something like:
char arr[8];
void test(void)
{
for (int i=0; i<7; i++)
arr[i]=arr[i+1];
}
on gcc -O2, and it will use memmove to replace a seven-iteration loop. Clever, stupid, or both?
More interestingly, when using either clang or gcc in C++ mode (or clang even in C mode), endless loops can cause arbitrary memory corruption even if every individual operation performed by the program sequentially would have fully defined behavior.

flatfingertuning
Автор

Nice file on the bottom of the screen.

milkbone
Автор

With such a minimal producing different results, especially when you throw different compilers into the mix, the phrase 'never trust your compiler' always rings true.

ChrisM
Автор

Already see the headline: YouTuber claims C Compiler is sentient.

Lihinel
Автор

Around 2:02, I find it odd that the compiler recognizes to replace code with "memset" but does not recognize the implications of doing it under the conditions you have given . The compiler will always be a little bit dumb until we reach a phase that I don't really want to think about .

edwardmacnab