I am checking some terrible C source code; I haven't got any idea about how to maintain it or cooperate with it. But I found a very fundamental problem. It does NOT have a startup.asm; it has a startup.c using the powerful C extension "#pragma". So, the C runtime environment is setup by "#pragma section", "#pragma intvect", "#pragma asm". I quite worry about such a startup.c; so I contacted the FAE of our local distributor. The FAE is an experienced good engineer, but he told me that, this is not their standard way to setup C runtime environment; they definitely provided the startup.s from Day 1.
What will be the side-effect, when the C runtime environment is setup by the C extension "#pragma"?
"In this case, we are talking about assembler initialization - but assembler instructions in a C file instead of in a separate assembler file."
I am not sure if that (inclusion of assembler instructions in a C file) makes a big difference. end of the day, they produce the same result.
I do see a benefit to create a separate assembler file for those assembler instructions if you have tons of them -> essentially create a .asm start-up file.
but if the amount of assembler instructions is small, it probably makes more sense to include them in a .c file.
my point is that it is hard to make an absolute statement about whether it is right (or wrong) to embed assembler instructions in a .c file. it depends on many other factors.
"but if the amount of assembler instructions is small, it probably makes more sense to include them in a .c file."
That very much depends on used compiler.
Some compilers will remove support for source-level debugging if mixing assembler and C.
Some compilers will merge the compiler-generated assembler instructions with the inlined assembler instructions and then run everything through the optimizer, potentially resulting in an object file containing other instruction sequences than the programmer did write.
So in the general case, C and assembler shouldn't be mixed in the same file. Having assembler in a C file in the first place is outside of the C standard, so any such use should not be considered unless the specific compiler have specific documentation saying both how to do it and clearly documenting limitations or potential problems.
A compiler vendor normally ships sample startup files since there are a number of needs that must be fulfilled to make the C RTL work as expected and make the processor reach main() in a way fulfilling the requirements from the C standard. Not using the compiler-supplied startup file (with optional additions for supporting extra hardware) means that a developer have to take his chances about his own startup code being enough to fulfill all initialization requirements. Compiler vendors often do not write a document listing these requirements for the simple reason that they consider it enough to just ship a startup file.