Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion What is volatile?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex Vinokur  
View profile  
 More options Mar 17 2004, 2:52 am
Newsgroups: comp.lang.c
From: "Alex Vinokur" <ale...@big.foot.com>
Date: Wed, 17 Mar 2004 09:52:56 +0200
Local: Wed, Mar 17 2004 2:52 am
Subject: Re: What is volatile?

"Anil Akkur" <anilak...@yahoo.co.in> wrote in message news:d46b1147.0403162202.74cbd777@posting.google.com...
> Hi All,
> Please explain me exact meaning of "volatile" qualifier? Where exactly we use it?
> Please explain me with a code snippet.
> Thanks in advance.

--------------------------------------------------
Compiler : GNU gcc version 3.3.1 (cygming special)
--------------------------------------------------

====== C code : BEGIN ======
------ File foo1.cpp -------
int main(int argc, char** argv)
{
int i;
  i = argv[1][0];
  i = argv[1][1];
  return i;

}

----------------------------

------ File foo2.cpp -------
int main(int argc, char** argv)
{
volatile int i;
  i = argv[1][0];
  i = argv[1][1];
  return i;

}

----------------------------

====== C code : END ========

====== Compilation (No optimization): BEGIN ========

$ gcc -save-temps foo1.c

$ gcc -save-temps foo2.c

$ ls foo*.s
foo1.s  foo2.s  // Files containing assembler code

$ diff foo1.s foo2.s
1c1
<       .file   "foo1.c"
---

>       .file   "foo2.c"

====== Compilation (No optimization): END ==========

====== Compilation (Optimization O1): BEGIN ========

$ gcc -O1 -save-temps foo1.c

$ gcc -O1 -save-temps foo2.c

$ ls foo*.s
foo1.s  foo2.s  // Files containing assembler code

$ diff foo1.s foo2.s
1c1
<       .file   "foo1.c"
---

>       .file   "foo2.c"

15,16c15,20
<       movl    4(%eax), %eax
<       movsbl  1(%eax),%eax
---

>       movl    4(%eax), %edx
>       movsbl  (%edx),%eax
>       movl    %eax, -4(%ebp)
>       movsbl  1(%edx),%eax
>       movl    %eax, -4(%ebp)
>       movl    -4(%ebp), %eax

====== Compilation (Optimization O1): END ==========

Conclusion.

No optimization : Assembler code for foo1.c and foo2.c is identical.
Optimization O1 : Assembler code for foo1.c and foo2.c is different.

--
   Alex Vinokur
     mailto:ale...@connect.to
     http://mathforum.org/library/view/10978.html


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google