473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

volatile short

Could anybody help me to understand what a volatile short variable should be used for? Whats the difference with short?
Jun 28 '07 #1
3 3536
Meetee
931 Expert Mod 512MB
Could anybody help me to understand what a volatile short variable should be used for? Whats the difference with short?
A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears.The compiler needs to know that this value may be changed by some external force when it optimizes the code. The declaration without volatile behaves as normal short type variable

Regards
Jun 28 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Another way of saying this is that since the value of the variable may change ouside the control of the compiler, the compiler should make no assumptions about it. Like, put it in a register instead of making it a variable. volatile tells the compiler be dang sure you create a variable.
Jun 28 '07 #3
Another way of saying this is that since the value of the variable may change ouside the control of the compiler, the compiler should make no assumptions about it. Like, put it in a register instead of making it a variable. volatile tells the compiler be dang sure you create a variable.
Another reason i think is to avoid the intelligent compilers from skipping the dead code.
a scenario where a variable is declared and not explicitly used, will be removed by the compiler. But when "volatile" keyword is used its not the case
Jun 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Marcin Kalicinski | last post by:
Hi all, I have a problem with 'volatile' use in C++. The function get_clocks() below tries to use a 16 bit hardware counter to count time. The counter overflows very often. But an interrupt is...
4
by: Rick | last post by:
Hi, What exactly is the volatile keyword for in C? and when should we use it/ avoid it? Thanks Rick
7
by: r_o_h_i_t | last post by:
Can anybody please tell me the complete properties if volatile variables in C. And what are specific uses of them? Thanks in advance.
9
by: Tim Rentsch | last post by:
I have a question about what ANSI C allows/requires in a particular context related to 'volatile'. Consider the following: volatile int x; int x_remainder_arg( int y ){ return x % y; }
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
13
by: yaron | last post by:
Hi all, let be focus on sigle processor machine 32 bits. 1. with multi-threaded on single processor machine 32bit do i have to sync access to atomic get/set properties of type less then 32 bits...
3
by: Amir Shitrit | last post by:
Hello. How come it's safe to read non-volatile fields that are shared across threads using locks for synchronization (for example, Monitor.Enter or EventWaitHandle), but it's not safe to access...
6
by: titan nyquist | last post by:
Can you make volatile structures in C#? I have a static class, to have "global" variables. This allows the whole program to see them. I make them "volatile" to avoid multi- threading accessing...
2
by: CptDondo | last post by:
I'm trying to write what should be a simple program, and it keeps hanging if I use volatile.... The program, stripped of its error checking, is this: unsigned short * start; unsigned short *...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.