public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* type promotion for fixed point types
@ 2009-02-27 20:58 Sean D'Epagnier
  2009-02-27 21:07 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Sean D'Epagnier @ 2009-02-27 20:58 UTC (permalink / raw)
  To: gcc, fu

Hi,

I just added support for printf and scanf of fixed point types to avr
libc.  I wanted to handle:

Currently "accum" and "fract" work, but not "short accum" or "short fract"

  This is not a problem for integers currently since they get type
promoted when passed with stdarg.

There is nothing in the fixed-point standard that is for or against
this.. it seems logical that "short accum" be promoted to "accum" and
"short fract" be promoted to "fract" in this case.

Does anyone have any opinions on this?

Thanks,
Sean

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: type promotion for fixed point types
  2009-02-27 20:58 type promotion for fixed point types Sean D'Epagnier
@ 2009-02-27 21:07 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2009-02-27 21:07 UTC (permalink / raw)
  To: Sean D'Epagnier; +Cc: gcc, fu

On Fri, 27 Feb 2009, Sean D'Epagnier wrote:

> Hi,
> 
> I just added support for printf and scanf of fixed point types to avr
> libc.  I wanted to handle:
> 
> Currently "accum" and "fract" work, but not "short accum" or "short fract"
> 
>   This is not a problem for integers currently since they get type
> promoted when passed with stdarg.
> 
> There is nothing in the fixed-point standard that is for or against
> this.. it seems logical that "short accum" be promoted to "accum" and
> "short fract" be promoted to "fract" in this case.
> 
> Does anyone have any opinions on this?

The promotion of "float" to "double" when passed to a variadic function is 
considered a legacy anomaly.  Thus, the default argument promotions 
(applied to variable arguments) should be considered to be the "integer 
promotions", float to double, and nothing else.  (In particular, it is 
deliberate that float _Complex does not promote to double _Complex - see 
DR#206 - and likewise float _Imaginary (not supported by GCC) does not 
promote to double _Imaginary.)

Unless your promotion is defined as being one of the "integer promotions", 
it should thus not occur.  Your printf implementation should call va_arg 
with the correct unpromoted type when it is passed an appropriate one of 
the fixed-point printf formats defined in the fixed-point TR.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-27 21:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-27 20:58 type promotion for fixed point types Sean D'Epagnier
2009-02-27 21:07 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).