Volatile in dos application

This is a discussion on Volatile in dos application within the C++ Programming forums, part of the General Programming Boards category; I have searched the forum and found that volatile keyword is used so that other programs are allowed to modify ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    Volatile in dos application

    I have searched the forum and found that volatile keyword is used so that other programs are allowed to modify it.

    Then why is it provided in dos programming which does not support multiprogramming concept.

    Second question what is use of
    Code:
    const volatile int i;

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by vaibhav
    I have searched the forum and found that volatile keyword is used so that other programs are allowed to modify it.
    That's probably not what you read.

    Quote Originally Posted by vaibhav
    Then why is it provided in dos programming which does not support multiprogramming concept.
    DOS had interrupts.

    volatile is used when something outside of your code can modify the variable.

    And a const volatile variable is one that your code can't change, but something else can -- like a processor register or some such.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    311

    Arrow

    Actually what volatile does is more like forces the compiler to allocate ordinary memory for a variable and to assume nothing when working with the variable. const volatile is really only used for cute little examples in programming forms.

    for example
    Code:
            const int i = 6;
    	const_cast<int &>(i)=9;
    	std::cout << "i=" << i << std::endl;
    is allowed to output "i=6" as the const has told the compiler that it can assume that there will be a 6 wherever "i" appears.
    Code:
    	const volatile int i = 6;
    	const_cast<int &>(i)=9;
    	std::cout << "i=" << i << std::endl;
    is requred to output "i=9"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 08:27 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. File systems?? (Winxp -> DOS)
    By Shadow in forum Tech Board
    Replies: 4
    Last Post: 01-06-2003, 09:08 PM
  4. Project Type for DOS Application
    By Visual Develope in forum C++ Programming
    Replies: 8
    Last Post: 05-06-2002, 03:37 PM
  5. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21