[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: maxresdefault.jpg (33 KB, 1280x720)
33 KB
33 KB JPG
does the C language first compile to assembler and then to binary?
>>
>>108227332
Not since 1998, grandpa zoomer.
>>
>>108227338
what about Python?
does it first compile to C++ and then to binary?
>>
>>108227343
It does, but Python is a subhuman nocoder language anyway.
>>
.
>>
>>108227332
You should read up these terms:
language
compiler
assembler
machine code
linker
>>
>>108227533
will this bring me closer to job prospects
>>
>>108227820
yeah they ask about it in the McDonald's job interview
>>
>>108227332
the "language" doesn't do things in that way, it is done to the language.
but yes, compilers first compile to assembly, then assemble said to object files and lastly link those object files into a finished executable.
you can cut those steps short using gcc or clang using
-E, to stop just after preprocessing (so all the #include and #define)
-S, to stop just after compiling
-c, to stop just after assembling
>>
>>108229478
don't forget intermediate representation (GIMPLE or LLVM IR).
>>
>>108227343
It first compiles to special Python bytecode and then it runs the bytecode using the interpreter program.
As of very recently there's also an experimental feature that compiles it to LLVM IR which is then compiled to binary/machine code.
>>
>>108230437
sure. but I think that'd be too much for someone asking whether there's an assembly intermediate.

what's your favourite IR? pure AST, sea of nodes, SSA?
in my homebrew compiler I've landed on something similar to sea of nodes, but not sure. I collect all subsequent operations into a single block and simplify that as much as possible.
I haven't got around to doing proper reordering even across basic blocks, but some day I might.
>>
>>108229478
>compilers first compile to assembly
usually not
>>
>>108230702
>SSA?
SSA is nice, as it makes many basic blocks be effectively simple pure functions with very easy to reason about properties.
But the mapping of the input program to SSA can be quite complex. C is not the worst for that. (Some compiler versions don't scale well with the number of BBs.)
>>
>>108227332
C compiles into machine code which generates binary.
>>
>>108230881
gcc does, not sure how clang does it. does it go from IR to object files directly?
>>108230933
>makes many basic blocks be effectively simple pure functions
huh, yeah makes sense. for me it's that I've never deliberately designed my toy IR, it just grew on its own every time I needed to represent some new language structure.
>>
>>108227820
>job
shut up waggie, stop worshipping mammon
>>
>>108231295
>gcc does
no it doesn't retard. i explicitly mentioned GIMPLE above so retards like you could notice.
were you one of the retards in one of the rust threads a couple of days ago by any chance?
>>
The binary of your machine code is assembled by your compiled linker
>>
File: white_fox.jpg (601 KB, 2048x2732)
601 KB
601 KB JPG
>>108227332
Why would you ask a question that can easily be searched on a search engine?


No, the C compiler does not compile down to ASM without specifically flagging the compiler to do so.

It links and and assembles the code using the compilers built in code generation logic. This is also compiler specific. A GCC binary may be different than an LLVM C-LANG binary for example.
>>
>>108231913
alright you just don't know what you're talking about, good to know:]
>were you one of the retards in one of the rust threads a couple of days ago by any chance?
no
>>
>>108232298
>>108231913
it depends on the implementation. gcc does convert all front ends to assembly before running the assembler. it is usually just hidden because most people do not care what the assembly looks like or is. most of the pipeline is not written to a file. if you do `gcc file.c file2.c` it just spits out the binary and no object files, but it still creates the object files.
>>
>>108227338
>>108227332
save assembler listing is optional
>>
>>108232298
search engines stopped working in 2018, stop pretending we live in a world where google cache still exists
>>
File: file.png (167 KB, 1275x853)
167 KB
167 KB PNG
>>108231913
>>108230881
Did you really think we wouldn't notice?
>>108232657
>>108231295
This is correct.
>>
>>108232657
>>108232931
>what is -fdump-tree-* :S
>what is libgccjit :S
>>
>>108233087
>what is as file.s
>>
>>108227332
It depends on the specific compiler. Some compile straight to binary while others have an intermediate stage where it compiles to bytecode or assembly that's then compiled to binary. Cross-platform compilers usually compile to a intermediate stage first.
>>
>>108227332
Even visual c has an option to generate .asm … but it now says (for the last 10 years or so) that the asm is for informational purposes only and not guaranteed to assemble/compile.
>>
>>108233117
oh, i understand now. you're a jeet.
have a nice day.
>>
Modularity. retard.
People like having an inbetween assembler output.
>>
>>108227332
Most compilers don't actually do this but it seems to stick around in textbook diagrams and such.
As misconceptions go, it's a fairly harmless one.
>>
>>108234405
gcc does it, I know that
I'd be surprised if clang doesn't



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.