School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,127 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,051 people online right now. Registration is fast and FREE... Join Now!




Computer basics

 

Computer basics, Tutorials

chandansingh

21 Dec, 2008 - 12:42 AM
Post #1

New D.I.C Head
*

Joined: 20 Dec, 2008
Posts: 17



Thanked: 1 times
My Contributions
what is means of volatile words ?


User is offlineProfile CardPM
+Quote Post


no2pencil

RE: Computer Basics

21 Dec, 2008 - 01:20 AM
Post #2

i R L33t Skiddie, k?
Group Icon

Joined: 10 May, 2007
Posts: 13,494



Thanked: 303 times
Dream Kudos: 2875
Expert In: Goofing Off

My Contributions
Usually it's the memory (ram) that is referred to as volatile. This means that the power is required to safe the data. Your hard drive, floppy disk, ram drive, all of these devices STORE the data. They are designed to hold data without power. The device can be moved, & then later have power re-applied & the new computer (or device attached to it) can then read the data from that device.

When information is in memory (ram) however, once the power is removed, so is the data.

** Moved to Computer Support & Operating Systems **
User is online!Profile CardPM
+Quote Post

numerical_jerome

RE: Computer Basics

27 Dec, 2008 - 11:46 PM
Post #3

D.I.C Head
**

Joined: 16 Sep, 2007
Posts: 164



Thanked: 10 times
My Contributions
In the C/C++ types this indicates that this value may be modified outside of its declared scope. For example, if you are working with a memory mapped value (like you may see working directly with memory mapped BIOS, or some very rudimentary systems type work [drivers & TSR's]), it is reasonable to assume that some other program, or even a different function may access and change the value stored at that location, requiring the compiled program to "double-check" the value every time it needs to read from that location, as opposed to using a register, or optimizing out the read completely.

The practical upshot of this, for those not doing absurdly low level / microcontroller type stuff, is that declaring a variable as volatile can remove some unwanted compiler optimization.

For example, if we wanted to implement our own version of UNIX usleep():

CODE

// usleep(N) in posix systems runs a time delay loop for N microseconds
// also does some other stuff regarding interrupts that are way beyond this
// example

void usleep(int a)
{
   int b = 0;
   while(b < a)
   {
      b++;
   }
}


most modern compilers are smart enough to look at this and say (correctly) "it doesn't do anything, don't bother compiling / linking it", and optimize out all or most of the procedure, but with volatile:

CODE

void usleep(int a)
{
   volatile int b = 0;
   while(b < a)
   {
      b++;
   }
}


the compiler would assume that something is behind the scenes tinkering with "b", and will compile the loop more or less as desired.

Hope this helps,

-Jerome

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:29PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month