473,322 Members | 1,480 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,322 software developers and data experts.

using volatile ptrs ...

LBJ
lets say i have the following definition:

volatile char* p = 0x0a0a0a;

lets say p now points directly to cacheable memory, and lets also
say that this memory is currently cached. when p is accessed, will the
cache be hit, or will the program actually go out to DRAM (due to the
volatile qualifier)? I am guessing that the cache will be hit, and
that 'volatile' only means that internal registers to the cpu cannot
save *p. is that correct?
Nov 14 '05 #1
6 2805
LBJ <lb****@yahoo.com> scribbled the following:
lets say i have the following definition: volatile char* p = 0x0a0a0a; lets say p now points directly to cacheable memory, and lets also
say that this memory is currently cached. when p is accessed, will the
cache be hit, or will the program actually go out to DRAM (due to the
volatile qualifier)? I am guessing that the cache will be hit, and
that 'volatile' only means that internal registers to the cpu cannot
save *p. is that correct?


This question is entirely implementation-specific. The C language does
not even specify the terms "cacheable memory" or "DRAM".
Even assigning a direct address to a pointer in the first place causes
undefined behaviour. As far as the C language cares, a legal outcome of
the above code is to paint your screen purple with pink spots and print
"Cuckoo Cashew!" seventeen times in random locations, while renaming
every file on your file system to a line from "Finnegan's wake".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
Nov 14 '05 #2
LBJ wrote:
lets say i have the following definition:

volatile char* p = 0x0a0a0a;
Indeed, let's. Note that if you say it to a C
compiler, the compiler must issue a diagnostic message.
lets say p now points directly to cacheable memory, and lets also
say that this memory is currently cached. when p is accessed, will the
cache be hit, or will the program actually go out to DRAM (due to the
volatile qualifier)? I am guessing that the cache will be hit, and
that 'volatile' only means that internal registers to the cpu cannot
save *p. is that correct?


The C language has no notion of cacheable memory, of
cached memory versus uncached memory, of hitting a cache,
of DRAM, or of "internal registers." Your question can't
be answered in terms of the C language, but only with
reference the a particular implementation on a particular
platform -- and, of course, different implementations will
have different answers. Consult the documentation for the
implemenations of interest, or seek advice on newsgroups
devoted to them.

--
Er*********@sun.com

Nov 14 '05 #3
On Wed, 10 Nov 2004 13:16:40 -0800, LBJ wrote:
lets say i have the following definition:

volatile char* p = 0x0a0a0a;
As others have indicated this is not valid C, you need an explicit cast to
convert an integer to a pointer. The result in this case won't be
portable.
lets say p now points directly to cacheable memory, and lets also
say that this memory is currently cached. when p is accessed, will the
cache be hit, or will the program actually go out to DRAM (due to the
volatile qualifier)? I am guessing that the cache will be hit, and that
'volatile' only means that internal registers to the cpu cannot save *p.
is that correct?


This is a level of detail that the C language doesn't cover. volatile has
a couple of uses in standard C, e.g. in relation to signal handlers and
sig_atomic_t. However it is commonly used in platform-specific extensions
to the language (e.g. threading). The basic idea is that it indicates that
an object can be accessed asynchronously e.g. from a different
process/thread on a signal or interrupt as a hardware sensitive location
and so on. It suggests to an optimiser that it should not eliminate
actual accesses of that location. Having volatile objects cached but not
held in registers (or more specifically a read/write in the source causes
an actual read/write of the memory location holding the object) is a
common implementation but certainly not something that C specifies or
requires. C defines the behaviour of programs (and in the case of volatile
constructs not very tightly), it does not specify how implementations
should achieve that behaviour. The non-portability I mentioned at the top
i.e. lack of definition by C itself, tends to generate broad license for
how implementations deal with it.

Lawrence

Nov 14 '05 #4

In article <62*************************@posting.google.com> , lb****@yahoo.com (LBJ) writes:
lets say i have the following definition:

volatile char* p = 0x0a0a0a;
Let's assume that you have the necessary cast as well.
lets say p now points directly to cacheable memory, and lets also
say that this memory is currently cached. when p is accessed, will the
cache be hit, or will the program actually go out to DRAM (due to the
volatile qualifier)?


Neither. Your program will stop with a program check condition, and
a message will be sent to the user message queue (or job message
queue, if it's running in a non-interactive subsystem) noting the
error. If the message queue is in auto-answer mode, the program will
be cancelled and its spool file will contain a description of the
failure; otherwise, it will wait for a reply to the message. Typically
you will have the option of cancelling the program, debugging it, or
ignoring the program check - but in the last case you'll simply get
an immediate machine check which will only let you cancel the
program, IIRC.

Of course I'm assuming that you're using one of the conforming C
implementations for OS/400 V3R7, as is often[1] the case. Other
implementations may behave differently.

In OS/400 V3, and in later versions of OS/400 except for certain
special cases,[2] the implementation always produces a trap repre-
sentation when converting from an integer to a pointer. That's a
specific, real-world example of a conforming C implementation where
you cannot cast an integer to a pointer and successfully dereference
the latter.

As for your question regarding the "volatile" qualifier: the C
standard actually makes very few guarantees about volatile, and its
behavior is almost entirely a Quality of Implementation issue. So
you'll have to ask whoever wrote your compiler.
[1] Under certain other assumptions we need not go into here.

[2] The exceptions are the Licensed Internal Code, which forms the
lowest level of the OS; and the PASE environment, which was created
to support ill-behaved C programs. PASE gives the executing program
a one-TB memory object as its "address space", in which it is free
to muck about as it likes.

--
Michael Wojcik mi************@microfocus.com

"Well, we're not getting a girl," said Marilla, as if poisoning wells were
a purely feminine accomplishment and not to be dreaded in the case of a boy.
-- L. M. Montgomery, _Anne of Green Gables_
Nov 14 '05 #5
Lawrence Kirby wrote:
[ snip ] Lawrence


Is that you fred? Welcome back. We've missed you here.

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #6
On Thu, 11 Nov 2004 17:46:56 -0500, Joe Wright wrote:
Lawrence Kirby wrote:

[ snip ]
Lawrence


Is that you fred? Welcome back. We've missed you here.


Yes, that's me!

Lawrence

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: newsock | last post by:
Why need to qualify a member function "volatile"? Why need to qualify a object "volatile"? When need to "const_cast" away "volatile" of an object and a member function? I also saw some code...
4
by: Andrew | last post by:
Section 17.4.3 of the ECMA-334 C# Language Specification says 1 When a field-declaration includes a volatile modifier, the fields introduced by that declaration are volatile fields. 2 For...
1
by: jon wayne | last post by:
Hi Am trying to replace the classic switch case construct (am workng on a telecom stack devlpmnt)with an array of function ptrs. The problm am facing is that of indexing. - the case vals can be...
8
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
14
by: Ian Pilcher | last post by:
It's pretty common to see declarations such as: static volatile sig_atomic_t caught_signal = 0; C99 defines sig_atomic_t as a "... (possibly volatile-qualified) integer type of an object that...
6
by: red floyd | last post by:
I have a struct that maps onto a set of memory mapped registers. I access this via a pointer. Is it better to declare it as pointer to a volatile struct, or to declare the individual members as...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
3
by: Rakesh Kumar | last post by:
Hi - I am actually trying to get my feet in multi-threaded C++ programming. While I am aware that the C++ standard does not talk about threads (at least, for now - in C++03) - my question is more...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.