Ternary operator and memory access

  • Thread starter Udo A. Steinberg
  • Start date
K

Keith Thompson

Ancient_Hacker said:
Yes, there can be very very touchy variables, where something that
seems innocuous, like just evaluating their address can cause
side-effects. For example on machines with many segment registers,
just loading up an address into an address register can cause "seg
fault"-like traps. Best example, the x86 in 16-bit protected mode.
Peeking at any segment value that hasnt been explicitly allocated to
your program will trap out. You're typically handed just 4 out of 8192
possible segments, so the odds arent good if the goods are odd.

So compilers, when in that code-generating mode, have to be very
conservative. No loading up of arbitrary addresses, no stuffing extra
info into the top bits of pointers.

On the other hand, the compiler is in control of the generated code,
and can do whatever it likes as long as no strictly conforming program
can tell the difference. It's free to load an arbitrary address if it
knows that doing so won't have any visible side effects -- and, since
it's the compiler, it's in a position to know that (unlike the user,
who should assume that it can invoke undefined behavior). Similarly,
if it knows that stuffing information into the top bits of pointers
won't cause any change in behavior (e.g., it happens to know that the
top N bits are ignored by the hardware and/or operating system), it's
free to do that as well.
 

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
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top