Compailation

J

jamesjoy

if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James
 
T

tmp123

if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James

Not the preprocessor, because it is not a preprocessor related
statement (at least, not the usual preprocessors).

The compiler can do several actions. It depends of how improved it is:
From the point of view of messages, one warning or error if A is not
enough big to keep the resulting value.
From the point of view of execution, it can evaluate the result at
compilation time and generate code to assign this result to A. Or it
can compute code that evaluates the expression and assigns it.


Kind regards.
 
V

Vladimir S. Oka

if i write

A = 512 * 512 ;

for an 8-bit processor,compailer

who will compute the value? pre-processor or the compailer generate
assembly code for 8-bit processor to find the value,

can any body help me... by explaining this, how des this work

thanks
James

The fact you're using an 8-bit processor is much less (if at all)
important than the type of `A`. If `A` is not wide enough for the
result of the expression on the right, a compiler should issue a
warning (but is not required to). Decent compilers will allow you to
use more than 8-bit variables even on 8-bit architectures.

As for how and when the expression is calculated, that depends on the
compiler, and also on the options you pass to it. One thing is certain,
though: this is /not/ done by pre-processor.

Any half-decent compiler should calculate th value of the expression
during compilation, and generate only the store instruction (NB, it
will also do any operations that may be required to force the value
into `A`).

It may be possible to force the compiler to actually generate the code
for multiplication, but why would one want to do that?
 
C

Charles Richmond

tmp123 said:
Not the preprocessor, because it is not a preprocessor related
statement (at least, not the usual preprocessors).

The compiler can do several actions. It depends of how improved it is:
From the point of view of messages, one warning or error if A is not
enough big to keep the resulting value.
From the point of view of execution, it can evaluate the result at
compilation time and generate code to assign this result to A. Or it
can compute code that evaluates the expression and assigns it.
It certainly *can* be computed at compile time. But I have used
compilers that were *so* bad...that such constant expressions had
code generated for them, and were computed at execution time.
 

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

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top