avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Urgent Queries about AVR-GCC


From: Neil Johnson
Subject: Re: [avr-gcc-list] Urgent Queries about AVR-GCC
Date: Tue, 3 Jun 2003 17:01:33 +0100 (BST)

Hi,

On Tue, 3 Jun 2003, E. Weddington wrote:
> Suresh B Joshi wrote:
> > (2) When using the switch statement, even if the control
> >     expression is an unsigned char variable, it is promoted
> >     to 16 bit unsigned int, by eor R25,R25 instruction.
> This has to be checked against the C standard (Jörg, do you know if this
> applies?). Just because Borland C++ 5.5 does one thing, doesn't mean that it's
> using ISO C only.

I've just checked the ANSI C standard (1990 edition) and as far as I
understand it, there is no requirement to promote the controlling
expression to "int".  What the standard does say (section 6.6.4.2) is that
the type of the controlling expression must be of integral type, and an
integral type (section 6.1.2.5) includes the type char, the signed and
unsigned integer types, and the enumerated types.

So, I think the Borland compiler is doing well, and GCC is not.

> > example for (2)
> > ===============
> >     1812:       08 95           ret
> >     1814:       08 95           ret                     // ret SHOULD NOT
> > APPEAR ONE BELOW THE OTHER
>
> The "2 rets" are probably an artifact of your C code. You will have to post a
> listing of mixed C and assembly. I highly doubt the compiler is generating a
> spurious ret.

Mmmm...my guess (and until we see the code it is only a guess) is that
immediately after the switch block is a return (or the end of the
enclosing function).  Now, when the compiler comes to emit the code for
the break, it sees that the target is a return, so instead of emitting a
jump to a return, it simply emits a return.  And so on, even for the last
break statement.  Then the code generator reaches the end of the function
and emits a return intruction.  But since this is immediately after the
end of the switch block, the result is the appearence of two "ret"s in the
output.

But, as I said, this is a guess at the moment.

Neil

--
Neil Johnson :: Computer Laboratory :: University of Cambridge ::
http://www.njohnson.co.uk          http://www.cl.cam.ac.uk/~nej22
----  IEE Cambridge Branch: http://www.iee-cambridge.org.uk  ----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]