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 7565407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:08:49+00:00 2026-05-30T14:08:49+00:00

I tried to examine how the this code will be in assembly: int main(){

  • 0

I tried to examine how the this code will be in assembly:

int main(){
  if (0){
    int x = 2;
    x++;
  }
  return 0;
}

I was wondering what does if (0) mean?

I used the shell command g++ -S helloWorld.cpp in Linux

and got this code:

    .file   "helloWorld.cpp"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    movl    $0, %eax
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
    .section    .note.GNU-stack,"",@progbits
  1. I expected that the assembly will contain some JZ but where is it?
  2. How can I compile the code without optimization?
  • 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-30T14:08:51+00:00Added an answer on May 30, 2026 at 2:08 pm

    There is no direct, guaranteed relationship between C++ source code and
    the generated assembler. The C++ source code defines a certain
    semantics, and the compiler outputs machine code which will implement
    the observable behavior of those semantics. How the compiler does this,
    and the actual code it outputs, can vary enormously, even over the same
    underlying hardware; I would be very disappointed in a compiler which
    generated code which compared 0 with 0, and then did a conditional
    jump if the results were equal, regardless of what the C++ source code
    was.

    In your example, the only observable behavior in your code is to return
    0 to the OS. Anything the compiler generates must do this (and have
    no other observable behavior). The code you show isn’t optimal for
    this:

    xorl %eax, %eax
    ret
    

    is really all that is needed. But of course, the compiler is free to
    generate a lot more if it wants. (Your code, for example, sets up a
    frame to support local variables, even though there aren’t any. Many
    compilers do this systematically, because most debuggers expect it, and
    get confused if there is no frame.)

    With regards to optimization, this depends on the compiler. With g++,
    -O0 (that’s the letter O followed by the number zero) turns off all
    optimization. This is the default, however, so it is effectively what
    you are seeing. In addition to having several different levels of
    optimization, g++ supports turning individual optimizations off or on.
    You might want to look at the complete list:
    http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/Optimize-Options.html#Optimize-Options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
This is a pretty odd situation I have here. I have used a piece
I just submitted this to Apple Support, but I'm wondering if anyone here has
For instance, I've tried things like this, which doesn't work: mydict = { 'funcList1':
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried following the instructions here: How to use Google app engine with my own
Tried a bunch of things but I can't get it to work consistently amid
tried to find the answer by googling and in MSDN but with no luck.
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools

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.