What does it mean

R

rsk

Hi Friends,

Can you please explain me what's the menaing of the following statement

*((volatile uint *) 0x00450000) = 0x00012345;

With Regards,
SS..
 
M

mdler

It means

(volatile uint *) 0x00450000
a pointer to a place in memory

*((volatile uint *) 0x00450000)
this is the memory it points to


*((volatile uint *) 0x00450000) = 0x00012345;
the memory is filled with a number

The procedure looks not save to use!
U are filling hard a peice of the memory without knowing anything
about this memory.

Greetings Olaf
 
R

Richard Heathfield

rsk said:
Hi Friends,

Can you please explain me what's the menaing of the following statement

*((volatile uint *) 0x00450000) = 0x00012345;

At a syntactical level, it means "convert 4521984 to a pointer to a
volatile uint (possibly losing information in the process), and set the
value of the thus-pointed-to uint object (which may not exist, or which
may not be a uint, or which may not be properly aligned for a uint) to
74565, and to Hades with the consequences".

At the behavioural and semantic levels, the C language imposes no meaning
on the code - the uint is undefined, and so is the behaviour.
 
M

Martin Wells

rsk:
*((volatile uint *) 0x00450000) = 0x00012345;


This is platform-specific, non-portable code.

What it does is the following:

Treat the memory address 0x00450000 as if it were storage for
uint, and then store the value 0x00012345 at that address.

The volatile, from what I can gather, is superfluous (...but then
again your particular system might have something funky going on).

In the realms of portable programming though, the behaviour of the
statement is not defined by the Standard so it can do (or not do)
whatever it wants.

Martin
 
A

Army1987

It means

(volatile uint *) 0x00450000
a pointer to a place in memory

*((volatile uint *) 0x00450000)
this is the memory it points to


*((volatile uint *) 0x00450000) = 0x00012345;
the memory is filled with a number

The procedure looks not save to use!
U are filling hard a peice of the memory without knowing anything
about this memory.

Supposing the OP copied that statement from somewhere, it is very
likely that whoever wrote it *did* know that. (Of course that
knowledge is OT here.)
BTW
s/save/safe/
s/U/You/
s/peice/piece/
 
R

Richard Tobin

*((volatile uint *) 0x00450000) = 0x00012345;
[/QUOTE]
The volatile, from what I can gather, is superfluous (...but then
again your particular system might have something funky going on).

Presumably it's to ensure that the compiler doesn't think "I just set
that location to that value a few lines up, so I don't need to do it
again".
In the realms of portable programming though, the behaviour of the
statement is not defined by the Standard so it can do (or not do)
whatever it wants.

The standard defines the volatile modifier and allows thet casting of
integers to pointers precisely so that you can do this kind of thing,
so a compiler that really did "whatever it wants" would be a poor one.

-- Richard
 
T

Tor Rustad

Martin said:
rsk:



This is platform-specific, non-portable code.

This look like low-level code, perhaps a device driver, which is
typically written in C.

What it does is the following:

Treat the memory address 0x00450000 as if it were storage for
uint, and then store the value 0x00012345 at that address.

The volatile, from what I can gather, is superfluous (...but then
again your particular system might have something funky going on).

Not at all. The type qualifier volatile, might be rather important here,
when you want to touch HW, volatile tell the program *not* to just
access the cache (and the compiler not to optimize).
 
K

karthikbalaguru

This look like low-level code, perhaps a device driver, which is
typically written in C.




Not at all. The type qualifier volatile, might be rather important here,
when you want to touch HW, volatile tell the program *not* to just
access the cache (and the compiler not to optimize).

Volatile is a Qualifier.
It is very common in Embedded to declare status register as volatile.
It implies that it can be changed by external hardware at any point of
time during the lifetime of the program and
the compiler must not optimise it if it is not used in the current
program.
It is for optimisation .

Karthik Balaguru
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top