Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

The usage of volatile and its difference from const volatile

Status
Not open for further replies.

raja.bhavanam

Junior Member level 3
Junior Member level 3
Joined
Nov 22, 2005
Messages
28
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,502
volatile unsigned short emif

what are the uses of volatile and what is the difference between
volatile and const volatile ?
 

C-Man

Advanced Member level 4
Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,189
Re: uses of volatile

Look here:


I va never seen const volatile ...

best regards
 

sinu_gowde

Full Member level 2
Full Member level 2
Joined
Nov 10, 2005
Messages
135
Helped
32
Reputation
64
Reaction score
12
Trophy points
1,298
Activity points
3,488

echo47

Advanced Member level 6
Advanced Member level 6
Joined
Apr 7, 2002
Messages
3,933
Helped
638
Reputation
1,274
Reaction score
90
Trophy points
1,328
Location
USA
Activity points
33,176
uses of volatile

volatile means that something else besides your code can modify the object.
The C standard says: an object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects.

const volatile means that your code can't modify the object but something else can.
The C standard gives an example:
extern const volatile int real_time_clock;
may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.
 

mowgli

Full Member level 2
Full Member level 2
Joined
Apr 5, 2002
Messages
147
Helped
34
Reputation
68
Reaction score
11
Trophy points
1,298
Activity points
1,348
Re: uses of volatile

Hallo all,
just to give a practical example: I'm working on a custom board with a DSP of C64xx family by Texas Instruments, which interfaces with an external custom bus through a set of 16-bit registers implemented in a FPGA connected to the DSP EMIF.
The DSP is programmed in C/C++ and to access to the FPGA registers I declared a set of pointers of the type

volatile unsigned short * register_xx

I must use this type declaration for 2 reasons:
1) registers on FPGA are written by other devices connected to the external bus
2) Code Composer Compiler sometimes (very often) interprets these registers as variables that don't change (because changes are made outside the SW) and so it discard from the compiled executable code and nothing works as expected.

I hope this example will help to understand.

Bye
Mowglii
 

ashish sharma

Full Member level 2
Full Member level 2
Joined
Jul 6, 2004
Messages
132
Helped
9
Reputation
18
Reaction score
5
Trophy points
1,298
Activity points
1,120
Re: uses of volatile


Hi
Both volatile and const volatile **broken link removed** are valid qualifiers in c language.

for your info let me explain it by a simple example

Say you have two programs p1 and p2 and you have declared a variable x as volatile and y as const volatile. Now just simply x can be changed or altered by p1 as well by p2 however y can be altered by p2 but not by p1 .

The application of this declaration is that the ports in microcontrollers are declared as constant volatile.


**broken link removed**
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top