top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why cc -S 1.c put the output in 1.s while cc -E 1.c does the same on stdout?

0 votes

While compiling step by step if we don't include -o while generating 1.i it will not create a new file and write the output on stdout, but in case of generating 1.s/1.o if we don't write -o it is automatically creates a new file and writes data into it. Why?

posted Jun 15, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Not able to understand anything...
For an Example, if we have 1.c file,
then if we do , "cc -E 1.c " : then it will print everything on stdout,
but if we do, "cc -S 1.c" : then it will create a new file called 1.s and write the data into it,
Why it is like this?
Hope my question is clear now.

1 Answer

+1 vote

Short answer is this is how it is designed, following is the documentation of -S and -E

Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix ‘.c’, ‘.i’, etc., with ‘.s’.
Input files that don't require compilation are ignored.

Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output. Input files that don't require preprocessing are ignored.

answer Jun 15, 2015 by Salil Agrawal
Similar Questions
+2 votes
struct marks {
  int a:1;
  int b:2;

int main() {
  struct marks obj={1,6};
  printf("%d %d\n",obj.b,obj.a);
+3 votes

There are Database Backup and restore utilities for RDBMS Systems.
The Backup program generates a (.Bak) Binary File as output which can later be restored in case the Database crashes.

What could be the Algorithm/s in database backup/s and restore programs ?. i.e. C/C++ Programming logic/Algorithm.

+4 votes

I am wanting to extract variable names and their size (int, char and etc.) from a c file.
Is there any way to extract that type of information?