Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

This is a common C bug. You write a MAX macro, then call MAX(m++, n++). The preprocessor pastes the text, so it becomes (m++ > n++) ? m++ : n++. The smaller one increments once. The larger one increments twice. Stanford CS107, lecture 12

29,707 görüntüleme • 2 ay önce •via X (Twitter)

30 Yorum

TempeTeaParty profil fotoğrafı
TempeTeaParty2 ay önce

This isn't so much a coding bug as it is a comprehension problem on the part of the programmer. How can this be common?

FM profil fotoğrafı
FM2 ay önce

It's interesting that the `inline` keyword is still not standard in C. It could've saved a lot of headache.

Max Sanna profil fotoğrafı
Max Sanna2 ay önce

I would never dream, not even by mistake, of using this macro in this way

Ali 🦁 profil fotoğrafı
Ali 🦁2 ay önce

This isn't a 🐞 this is expected preprocessor behavior! Some compilers might resolve the issue though

jhonny profil fotoğrafı
jhonny2 ay önce

Use Claude or GPT sol or Grok

proc0 profil fotoğrafı
proc02 ay önce

You don't use ++ more than once in the same statement, it's undefined behavior.

Dark Goldenrod profil fotoğrafı
Dark Goldenrod2 ay önce

I almost never use inline ++ or --. Yeah, it is an entire 3 seconds faster to type: arr[ idx++ ] = item than: arr[ idx ] = item; idx++; but it's slower to read every time.

Zavian profil fotoğrafı
Zavian2 ay önce

Become a teacher become a dev solana:5yC9BM8KUsJTPbWPLfA2N8qH1s9V8DQ3Vcw1G6Jdpump, become a ai video creator, what moore?

Benathon profil fotoğrafı
Benathon2 ay önce

I would never do that

Mickey Stewart profil fotoğrafı
Mickey Stewart2 ay önce

I remember watching this Stanford cs class on iTunes U when all these universities first started to make these available. These were awesome and So was Harvards CS50.

Advanced SuperSilly Intelligence profil fotoğrafı
Advanced SuperSilly Intelligence2 ay önce

The human suffering needs to end. Thank goodness for AI.

ashrealite profil fotoğrafı
ashrealite2 ay önce

I cant believe we whiteboard dimwitted shit like this in supposed prestigious universities.

∂≈∞ --- ∫∫∫∆∏∑∫∫∫ π⃜÷⃜×⃜•⃜|⃜¶⃜∆⃜$⃜%⃜|⃜+⃜ profil fotoğrafı
∂≈∞ --- ∫∫∫∆∏∑∫∫∫ π⃜÷⃜×⃜•⃜|⃜¶⃜∆⃜$⃜%⃜|⃜+⃜2 ay önce

Master tetsuo, your posts brighten my day. I am grateful that I discovered your account.

mutex.up profil fotoğrafı
mutex.up2 ay önce

That's not a C bug, that's simply correct text substitution by the preprocessor. Use the -E flag to check the preprocessed code if unsure. "inline" functions are safer, and "const" constants can be seen by a debugger. Understand your tools.

Matcha profil fotoğrafı
Matcha2 ay önce

I guess this is why I'm killing macros and replacing with __inline__ functions. AS I UNderstand it, the __inline__ functions expand to code within the calling location just like a macro, but without all the macro gotchas (like this one).

Augustus profil fotoğrafı
Augustus2 ay önce

Today, you need a really good reason to use defines. Inline functions > defines

smyanthota profil fotoğrafı
smyanthota2 ay önce

gcc statement expressions with typeof kill the double-eval, or just use an inline function and move on

Abbas Banu Vohra profil fotoğrafı
Abbas Banu Vohra2 ay önce

thanks thats why i tRUST because it (its designers) know that increment/decrement ops are pain in the ... : abv_bay_yanlis_8647_DMGINXL

Unique.Aioli8518 profil fotoğrafı
Unique.Aioli85182 ay önce

It's a feature, not a bug (at least not a C bug, anyway)!

Youssef Afella profil fotoğrafı
Youssef Afella2 ay önce

Everyone think using a chair is safe but watch what happens when you beat the shit of someone with it

zaphodicus profil fotoğrafı
zaphodicus2 ay önce

It is not a bug but a programmer mistake. A function is much better and the compiler will inline it automatically is needed. The macro system, even if I love it, is full of traps

ElectraX profil fotoğrafı
ElectraX2 ay önce

That's not a bug.

泰多宝 profil fotoğrafı
泰多宝2 ay önce

the gcc statement-expression fix assigns each argument to a __typeof__ temp first, so the side effect happens exactly once.

gb profil fotoğrafı
gb2 ay önce

Except it's not that common... unless you're a beginner and don't know it's a macro (despite it being written in capitals) ofc.

Matthew profil fotoğrafı
Matthew2 ay önce

Ibit++ known zeros

kimiyoribaka profil fotoğrafı
kimiyoribaka2 ay önce

I don't like mid-expression incrementing to begin with, but doing multiple at once seems like it's really asking for trouble.

Wade Noam Sayen profil fotoğrafı
Wade Noam Sayen2 ay önce

These curated into a collection is massive win

Orion Night profil fotoğrafı
Orion Night2 ay önce

every C programmer learns this exactly once

Path of Totality profil fotoğrafı
Path of Totality2 ay önce

Maybe our preprocessors need to be a little smarter 😆

Steve Mac profil fotoğrafı
Steve Mac2 ay önce

I love these little clips!

Benzer Videolar