← Back to context

Comment by rep_lodsb

14 days ago

You might want to compare it to the "proper" version of the inline asm code, from this comment: https://news.ycombinator.com/item?id=40703314

Modern C is neither "low-level" or "high-level". It's defined for an abstract machine where integers can't overflow, null pointers can't be referenced, etc. And unless you follow all the rules, and add proper annotations for things like inline assembly, the compiler is free to do anything to your code.

The one advantage to this approach is that modern compilers can turn megabytes of auto-generated crap produced by string substitution macros into halfway decent machine language.

(And I freely admit that specifically Turbo Pascal produced really bad code, worse even than C compilers at the time, but the syntax is oh so much nicer IMHO)

I believe that MSVC inline asm allows referencing variables in the asm as it can parse and understand the asm (at least before they got rid of inline asm completely for 64 bit code).

AFAIK GCC does not attempt to parse the asm by design, as it is meant to be used for code that the compiler might not understand, so you have to describe input, outputs and side effects with annotations.