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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:30:15+00:00 2026-06-10T18:30:15+00:00

According to the Wikipedia site: http://en.wikipedia.org/wiki/Volatile_variable I copied its sample code for testing in

  • 0

According to the Wikipedia site:

http://en.wikipedia.org/wiki/Volatile_variable

I copied its sample code for testing in my laptop, but the two have no difference! Here is my GCC version info:

i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The C source code is

/* volatile_var.c */
#include <stdio.h>
int main() {
        /* in no_volatile_var.c there is no volatile here */
        volatile int a = 10, b = 100, c = 0, d = 0;
        printf("%d\n", a + b);

        a = b;
        c = b;
        d = b;

        printf("%d\n", c + d);
        printf("%d\n", a);
        return 0;
}

I compiled the no_volatile_var.c and volatile_var.c both with

gcc -S *.c

but the out is the same following

    .section    __TEXT,__text,regular,pure_instructions
    .globl  _main
    .align  4, 0x90
_main:
Leh_func_begin1:
    pushq   %rbp
Ltmp0:
    movq    %rsp, %rbp
Ltmp1:
    subq    $32, %rsp
Ltmp2:
    movl    $10, -12(%rbp)
    movl    $100, -16(%rbp)
    movl    $0, -20(%rbp)
    movl    $0, -24(%rbp)
    movl    -12(%rbp), %eax
    movl    -16(%rbp), %ecx
    addl    %ecx, %eax
    xorb    %cl, %cl
    leaq    L_.str(%rip), %rdx
    movq    %rdx, %rdi
    movl    %eax, %esi
    movb    %cl, %al
    callq   _printf
    movl    -16(%rbp), %ecx
    movl    %ecx, -12(%rbp)
    movl    -16(%rbp), %ecx
    movl    %ecx, -20(%rbp)
    movl    -16(%rbp), %ecx
    movl    %ecx, -24(%rbp)
    movl    -20(%rbp), %ecx
    movl    -24(%rbp), %edx
    addl    %edx, %ecx
    xorb    %dl, %dl
    leaq    L_.str(%rip), %rdi
    movl    %ecx, %esi
    movb    %dl, %al
    callq   _printf
    movl    -12(%rbp), %ecx
    xorb    %dl, %dl
    leaq    L_.str(%rip), %rdi
    movl    %ecx, %esi
    movb    %dl, %al
    callq   _printf
    movl    $0, -8(%rbp)
    movl    -8(%rbp), %eax
    movl    %eax, -4(%rbp)
    movl    -4(%rbp), %eax
    addq    $32, %rsp
    popq    %rbp
    ret
Leh_func_end1:

    .section    __TEXT,__cstring,cstring_literals
L_.str:
    .asciz   "%d\n"

    .section    __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
EH_frame0:
Lsection_eh_frame:
Leh_frame_common:
Lset0 = Leh_frame_common_end-Leh_frame_common_begin
    .long   Lset0
Leh_frame_common_begin:
    .long   0
    .byte   1
    .asciz   "zR"
    .byte   1
    .byte   120
    .byte   16
    .byte   1
    .byte   16
    .byte   12
    .byte   7
    .byte   8
    .byte   144
    .byte   1
    .align  3
Leh_frame_common_end:
    .globl  _main.eh
_main.eh:
Lset1 = Leh_frame_end1-Leh_frame_begin1
    .long   Lset1
Leh_frame_begin1:
Lset2 = Leh_frame_begin1-Leh_frame_common
    .long   Lset2
Ltmp3:
    .quad   Leh_func_begin1-Ltmp3
Lset3 = Leh_func_end1-Leh_func_begin1
    .quad   Lset3
    .byte   0
    .byte   4
Lset4 = Ltmp0-Leh_func_begin1
    .long   Lset4
    .byte   14
    .byte   16
    .byte   134
    .byte   2
    .byte   4
Lset5 = Ltmp1-Ltmp0
    .long   Lset5
    .byte   13
    .byte   6
    .align  3
Leh_frame_end1:


.subsections_via_symbols

According to Wiki’s explanation, there should be difference and the volatile edition should bigger than the non-volatile one. I compiled them into binary and find that there size is also the same.

Questions:

  • Does my llvm-gcc cause that?(latter I’ll test these code on Linux) or the Wiki’s explanation is error?
  • Both them compiled the same binary code(simply according to their size), so their print result is the same. But according to Wiki’s explanation, does the two print different screen output?

Update

This question is due to Wikipedia’s error on optimization setting, and have no related with what the title says. Should I close this question?

  • 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-06-10T18:30:16+00:00Added an answer on June 10, 2026 at 6:30 pm

    Use gcc -O3 to turn on optimizations and you should see a difference.

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

Sidebar

Related Questions

According to http://en.wikipedia.org/wiki/Producer-consumer_problem I want to simulate P/C problem using semaphore. I am getting
According to wikipedia! http://en.wikipedia.org/wiki/ORDBMS IBM's DB2, Oracle database, and Microsoft SQL Server, make claims
According to http://en.wikipedia.org/wiki/Heap_%28data_structure%29#Comparison_of_theoretic_bounds_for_variants , it takes Θ(logn) (which translates to O(logn)) to perform the
According to the Wikipedia (http://en.wikipedia.org/wiki/Buffer_overflow) Programming languages commonly associated with buffer overflows include C
Question: I am creating a wiki software, basically a clone of wikipedia/mediawiki, but in
According to this site http://www.searchable-pdf.com/content.php?lang=en&c=61 , a PDF can be searchable when a text
According to Wikipedia, the md5 sum of an empty string is d41d8cd98f00b204e9800998ecf8427e I confirmed
According to Wikipedia: IronScheme, an upcoming Scheme implementation, was planning to build upon the
According to Wikipedia this syntax looks correct... INSERT INTO dbo.metadata_type (name, publishable) VALUES (Content
According to this Wikipedia entry on the PNG format , a PNG image file

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.