Interview Answer Review

Thread Starter

Dadu@

Joined Feb 4, 2022
155
I've completed my graduation and am currently applying for the role of an embedded software developer. In several interviews, I've been about how a C program develop and steps. I've provided an explanation, but I'm unsure about its relevance and accuracy.

Here's my response:

Interviewer: Explain how a C program develop and steps.

My Response:
In a general C program, the process involves several steps. First, during preprocessing, the compiler performs tasks such as including header files and substituting values for defined names. Next, the compilation step checks for syntax errors and generates object files for each source file. Next, the assembler converts the assembly code into machine code. Finally, the linker ensures the correct linkage of functions and data, producing the final executable file.

Could someone review this explanation and suggest any improvements or corrections? I want to ensure I'm providing a relevant and accurate explanation during interview
 

WBahn

Joined Mar 31, 2012
32,704
The question, as stated, is vague. I suspect this might be a result of translating from some other language to English.

I first thought it was probably asking about how a developer develops a C program. This would be pretty open-ended, which is fine for an interview, with lots of possible answers.

The answer you gave seems to be much more closed-ended and answering the question of what are the steps in compiling a C program.

You answer is probably in the ballpark. However, you have one thing in the wrong order -- you say that object files are created and then the assembler converts that into machine code. But the object files ARE the machine code produced by the assembler (if there is one). Also, the phrase "generates object files" encapsulates the bulk of what the compiler is doing, so it might be worth breaking that down a little bit.
 

Thread Starter

Dadu@

Joined Feb 4, 2022
155
The question, as stated, is vague. I suspect this might be a result of translating from some other language to English.
Thank you for your feedback! I realize the question might have been a bit vague in asking about the C program's compilation process. To clarify, I was indeed seeking an explanation of the compilation steps.

Regarding the answer I provided, your insight is helpful. I see now that the order of object file creation and assembly was misplaced in my explanation.

My revised answer

Preprocessor: This is the initial step where directives like #include and #define are processed. It handles tasks like including header files and macro expansions.

Compiler: It takes the preprocessed source code and translates it into assembly code.

Assembler: The assembler then converts the assembly code into machine code or object code.

Linker: Finally, the linker combines multiple object files (generated by the assembler) and create an executable file.

Would you recommend restructuring the explanation to better highlight the compilation process's steps ?
 

WBahn

Joined Mar 31, 2012
32,704
That may be good enough, though it's basically a 30,000 ft view of the process.

It's probably worth mentioning before you start that the description you are about to provide is not the only one possible. For instance, many compilers don't generate assembly code, but rather generate machine code directly. It would also be good to add a sentence or two regarding how the compiler translates source code into assemble or what tasks the linker accomplished when combining object files.
 

ApacheKid

Joined Jan 12, 2015
1,762
Thank you for your feedback! I realize the question might have been a bit vague in asking about the C program's compilation process. To clarify, I was indeed seeking an explanation of the compilation steps.

Regarding the answer I provided, your insight is helpful. I see now that the order of object file creation and assembly was misplaced in my explanation.

My revised answer

Preprocessor: This is the initial step where directives like #include and #define are processed. It handles tasks like including header files and macro expansions.

Compiler: It takes the preprocessed source code and translates it into assembly code.

Assembler: The assembler then converts the assembly code into machine code or object code.

Linker: Finally, the linker combines multiple object files (generated by the assembler) and create an executable file.

Would you recommend restructuring the explanation to better highlight the compilation process's steps ?
It's not a bad answer, but I'd add a bit more detail. In most cases I've seen a compiler generates a object file, that file is usually in some well defined standard format and yes it contains machine instructions but also lots of metadata like initialized memory values, exported symbols and perhaps symbol table stuff.

It's not common (in my experience anyway) for a compiler to use assembler as an intermediate representation of the code. It is common for the compiler to generate human readable assembly listings as well as code, this is often a compilation option.
 
Top