Where do I find the assembly code for a procedure called in the GCC assembly output?

后端 未结 3 691
萌比男神i
萌比男神i 2021-01-16 13:32

I\'ve been playing around with the assembly output switch for GCC:

gcc -S -c helloworld.c

helloworld.c:

#i         


        
3条回答
  •  囚心锁ツ
    2021-01-16 13:54

    EDIT: this is not actually an answer to the original question, but since it's getting upvoted the info seems to be useful, so...


    It's an optimization by GCC. Since your string does not contain any formatting characters and ends with a newline, GCC replaces the call with puts which produces the same output but is much faster (since it doesn't need to scan the string for formatting specifiers). Try something like:

    int main(int argc, char *argv[]){
        printf("Hello World!\nargc=%d", argc);
        return 0;
    }
    

    And you will see your printf in the assembly.

提交回复
热议问题