Загрузка видео...

Не удалось загрузить видео

На главную

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 просмотров • 2 месяцев назад •via X (Twitter)

Комментарии: 30

Фото профиля TempeTeaParty
TempeTeaParty2 месяцев назад

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
FM2 месяцев назад

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

Фото профиля Max Sanna
Max Sanna2 месяцев назад

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

Фото профиля Ali 🦁
Ali 🦁2 месяцев назад

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

Фото профиля jhonny
jhonny2 месяцев назад

Use Claude or GPT sol or Grok

Фото профиля proc0
proc02 месяцев назад

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

Фото профиля Dark Goldenrod
Dark Goldenrod2 месяцев назад

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
Zavian2 месяцев назад

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

Фото профиля Benathon
Benathon2 месяцев назад

I would never do that

Фото профиля Mickey Stewart
Mickey Stewart2 месяцев назад

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
Advanced SuperSilly Intelligence2 месяцев назад

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

Фото профиля ashrealite
ashrealite2 месяцев назад

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

Фото профиля ∂≈∞ --- ∫∫∫∆∏∑∫∫∫ π⃜÷⃜×⃜•⃜|⃜¶⃜∆⃜$⃜%⃜|⃜+⃜
∂≈∞ --- ∫∫∫∆∏∑∫∫∫ π⃜÷⃜×⃜•⃜|⃜¶⃜∆⃜$⃜%⃜|⃜+⃜2 месяцев назад

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

Фото профиля mutex.up
mutex.up2 месяцев назад

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
Matcha2 месяцев назад

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
Augustus2 месяцев назад

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

Фото профиля smyanthota
smyanthota2 месяцев назад

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

Фото профиля Abbas Banu Vohra
Abbas Banu Vohra2 месяцев назад

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
Unique.Aioli85182 месяцев назад

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

Фото профиля Youssef Afella
Youssef Afella2 месяцев назад

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

Фото профиля zaphodicus
zaphodicus2 месяцев назад

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
ElectraX2 месяцев назад

That's not a bug.

Фото профиля 泰多宝
泰多宝2 месяцев назад

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

Фото профиля gb
gb2 месяцев назад

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
Matthew2 месяцев назад

Ibit++ known zeros

Фото профиля kimiyoribaka
kimiyoribaka2 месяцев назад

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
Wade Noam Sayen2 месяцев назад

These curated into a collection is massive win

Фото профиля Orion Night
Orion Night2 месяцев назад

every C programmer learns this exactly once

Фото профиля Path of Totality
Path of Totality2 месяцев назад

Maybe our preprocessors need to be a little smarter 😆

Фото профиля Steve Mac
Steve Mac2 месяцев назад

I love these little clips!

Похожие видео