On Fri, 08 Sep 2000, you wrote:

> > Who need numbers in an arbitrary base anyway? Hexadecimal, decimal and
> > binary are enough. Octal is supported by many languages, but it is rarely
> > used in practice (the only use I know is Unix file permissions).
>
> Arbitrary base is easily implemented and might be useful in some cases. I
> don't know when really. But I want to give the possibility.

In the very few cases anyone needs it, they can simply take a calculator and 
convert the number to decimal.

> > Please don't use the C system for header files. It is better to make
> > the assembler remember which header files are already included and
> > don't process a single header file twice.
>
> I preprocess the source with gcc -E -P -C. Of course this implies that I
> do use the C system for header files. I just don't feel like rewriting the
> whole preprocessor again, while I do want its full functionality.

On most Unix systems, gcc is already installed. But on Windows or Mac, it 
would require a separate installation, which is quite large as well.

You don't have to write the whole preprocessor again, only the parts you 
need. Implementing file inclusion is straightforward.

I'm not in favor of using C macros in assembly. I'll give a simple example 
that shows a problem with C macros. First the program in Pascal:

program Example;
const X = 1 + 1;
begin
  writeln('2X = ', 2*X);
end;

Now the program that has been carelessly converted to C:

#define X 1 + 1
int main(void)
{
  printf("2X = %d\n", 2*X);
  return 0;
}

The Pascal program prints "2X = 4". However, the C program prints "2X = 3". 

Why? Because C macros use substitution: "2*X" is expanded to "2*1+1", the 
value of which is 3. Braces can be placed around the definition of X 
to avoid this kind of problem:
  #define X (1 + 1)
But the core of the problem is that the macro doesn't express what X really 
is: a constant.

I know that C also has constants using the "const" statement. However, these 
are actually variables that don't allow assignment. Using a typecast, you can 
change the value of such a "constant". But the most important difference is 
the way it's compiled: a constant is always placed in memory. But it's more 
efficient to calculate constant expressions in advance, which is impossible 
if the value is in memory. That's why C macros are often used in constants.

Bye,
                Maarten


****
Problems? contact [EMAIL PROTECTED] See also http://www.faq.msxnet.org/
****

Reply via email to