Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:02:34+00:00 2026-05-27T10:02:34+00:00

When my program is disassembled in gdb, I can see the address of buf

  • 0

When my program is disassembled in gdb, I can see the address of buf be pushed onto the stack, but I don’t see the format string pushed onto it. Any reason why this is? Is it a clever compiler optimization?

I’ve tried compiling a few different variations of printf statements to see if I could mimic the “%s” string (or address of it) not being pushed onto the stack, but I couldn’t do it.

This is the program code:

int main(int argc, char **argv) {

    char buf[128];
    if(argc < 2) return 1;

    strcpy(buf, argv[1]);

    printf("%s\n", buf);

    return 0;
}

compiled with gcc 4.5.2, 32 bit linux

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:02:34+00:00Added an answer on May 27, 2026 at 10:02 am

    Yes, it appears that gcc will throw away “printf (“%s\n”, buff)” and substitute “puts()” in its place:

    vi tmp.c =>
    
    #include <stdio.h>
    #include <string.h>
    
    int
    main(int argc, char **argv)
    {
        char buf[128];
        if(argc < 2)
          return 1;
    
        strcpy(buf, argv[1]);
        printf("%s\n", buf);
    
        return 0;
    }
    

    $ gcc -S -Wall -pedantic tmp.c
    less tmp.s =>

            .file   "tmp.c"
            .text
    .globl main
            .type   main, @function
    main:
            leal    4(%esp), %ecx
            andl    $-16, %esp
            pushl   -4(%ecx)
            pushl   %ebp
            movl    %esp, %ebp
            pushl   %ecx
            subl    $148, %esp
            movl    %ecx, -140(%ebp)
            movl    -140(%ebp), %eax
            cmpl    $1, (%eax)
            jg      .L2
            movl    $1, -136(%ebp)
            jmp     .L4
    .L2:
            movl    -140(%ebp), %edx
            movl    4(%edx), %eax
            addl    $4, %eax
            movl    (%eax), %eax
            movl    %eax, 4(%esp)
            leal    -132(%ebp), %eax
            movl    %eax, (%esp)
            call    strcpy
            leal    -132(%ebp), %eax
            movl    %eax, (%esp)
            call    puts
            movl    $0, -136(%ebp)
    .L4:
            movl    -136(%ebp), %eax
            addl    $148, %esp
            popl    %ecx
            popl    %ebp
            leal    -4(%ecx), %esp
            ret
            .size   main, .-main
            .ident  "GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-48)"
            .section        .note.GNU-stack,"",@progbits
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a PDP-8 Program. Kindly can any one disassemble it. Binary representation Octal
I am debugging a c program with gdb in linux terminal, I disassembled it
This code is a C program (bubble sort) disassembled into assembly. How can I
First, here is the C# code and the disassembled IL: public class Program<T> {
Program returns an error of, expected PWideChar instead of string procedure TForm1.Button1Click(Sender: TObject); var
This program runs just fine, but for some reason when I ask for an
Is there an easy way (like a free program) that can covert c/c++ code
when I disassembled following simple program in C: int main () { int a
When I use gdb to debug a program written in C, the command disassemble
I disassembled simple program written in C++ and there is a function: 080486a8 <_GLOBAL__I_main>:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.