POV-Ray : Newsgroups : povray.unofficial.patches : Why & has higher precedence than + or - in isosurface functions? : Re: Why & has higher precedence than + or - in isosurface functions? Server Time
2 Sep 2024 06:16:22 EDT (-0400)
  Re: Why & has higher precedence than + or - in isosurface functions?  
From: Thorsten Froehlich
Date: 6 Aug 2000 14:41:17
Message: <398db14d@news.povray.org>
In article <398d7a88@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>   This can't work this way. If it did, then if you make this:
>
> char c = 1;
>
> the variable 'c' will have the value 0.
>
>   '1' is of type int.

Sorry, but you are misunderstanding the concepts here:  You have to view the
problem on a lower level than the C programming language.  You have to look
at the hardware:  In case of a memory based CPU architecture, an access to a
int casted to a char will have certain side effects that are usually
"hidden" by a compiler, however, especially in the early days of C it was
common to use the knowledge about the CPU the code would run on to increase
speed.

Even today you can use this trick of CPU dependency, i.e. when you want to
determine the endianess on the fly - simply cast an pointer to an int to a
char and look at the result on different architectures.  After all, C
explicitly allows low level programming; this makes it such an popular
language for implementing operating systems and embedded applications.

A good textbook explaining such issues is "Computer Organization and Design:
The Hardware/Software Interface" (ISBN 1558604286).  It uses the original
(32 bit) MIPS architecture as example for the assembler code (and there is a
software emulator of a simple MIPS system available - even one that runs on
Solaris).  It also explains how high-level language constructs are actually
implemented on the assembly level.  This is in particular useful if you want
to write efficient C/C++ code.
The only negative point is the US$80 price tag.  Anyway, it is available
even in a lot of European university libraries.  Alternatively, there will
surely be a lot of similar, but older books (usually covering the 68000 CPU
architecture) available in next to any library.


    Thorsten


____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.