Загрузка видео...
Не удалось загрузить видео
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

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?

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

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

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

Use Claude or GPT sol or Grok

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

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.

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

I would never do that

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.

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

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

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

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.

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).

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

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

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

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

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

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

That's not a bug.

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

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.

Ibit++ known zeros

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

These curated into a collection is massive win

every C programmer learns this exactly once

Maybe our preprocessors need to be a little smarter 😆

I love these little clips!
Похожие видео
Sensitive content
The movement, the colours, the soundtrack. C I N E M A 🚬
Panty & Stocking Archive
1,180,144 просмотров • 1 год назад

