public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43162] New: option to set the "promoted" type of parameters of calculus
@ 2010-02-24 11:30 etienne_lorrain at yahoo dot fr
2010-02-24 11:34 ` [Bug c/43162] option to set the "promoted" type of parameters of arithmetic pinskia at gcc dot gnu dot org
2010-02-25 5:13 ` bangerth at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: etienne_lorrain at yahoo dot fr @ 2010-02-24 11:30 UTC (permalink / raw)
To: gcc-bugs
In C, variables are promoted to unsigned int or int before operations like
adding or multiplying so that we have on ia32 PC:
unsigned char uc1 = 0x10, uc2 = 0x10;
printf ("0x%X\n", uc1*uc2); -> display 0x100
unsigned short us1 = 0x1000, us2 = 0x10;
printf ("0x%X\n", us1*us2); -> display 0x10000
That doesn't work for unsigned long long, by design we have:
unsigned u1 = 0x10000000, u2 = 0x10;
printf ("0x%llX\n", (unsigned long long)(u1*u2)); -> display 0x0
It "would be nice" to be able to set the size to promote operands before
operations to either int/unsigned (as now) or long long/unsigned long long
to have the intended result on lines like:
unsigned long long ull = u1 * u2; // with previous values of u1 and u2...
Nothing else should be changed by this option, default parameter size
of printf() should still be int/unsigned, so that a line like:
unsigned u3 = u1 * u2;
would be optimised to the same assembly instructions whatever the value
of the switch.
--
Summary: option to set the "promoted" type of parameters of
calculus
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: etienne_lorrain at yahoo dot fr
GCC build triplet: any
GCC host triplet: any
GCC target triplet: any
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43162
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/43162] option to set the "promoted" type of parameters of arithmetic
2010-02-24 11:30 [Bug c/43162] New: option to set the "promoted" type of parameters of calculus etienne_lorrain at yahoo dot fr
@ 2010-02-24 11:34 ` pinskia at gcc dot gnu dot org
2010-02-25 5:13 ` bangerth at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-02-24 11:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2010-02-24 11:33 -------
I think this is the wrong approach really. Learning C/C++ rules for arithmetic
operations and the promotion of types is not hard.
Also this is not calculus but simple arithmetic operations :).
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|option to set the "promoted"|option to set the "promoted"
|type of parameters of |type of parameters of
|calculus |arithmetic
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43162
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/43162] option to set the "promoted" type of parameters of arithmetic
2010-02-24 11:30 [Bug c/43162] New: option to set the "promoted" type of parameters of calculus etienne_lorrain at yahoo dot fr
2010-02-24 11:34 ` [Bug c/43162] option to set the "promoted" type of parameters of arithmetic pinskia at gcc dot gnu dot org
@ 2010-02-25 5:13 ` bangerth at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: bangerth at gmail dot com @ 2010-02-25 5:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from bangerth at gmail dot com 2010-02-25 05:12 -------
I don't think we should be doing this. GCC strives to be standards-conforming
and the requested feature would purposefully make us violate the standard.
There is a point for extensions, but I don't think changing the meaning
of a perfectly well-formed program is not what we should be doing. The
same effect can of course be achieved by simply adding the explicit cast
to the code.
W.
--
bangerth at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at gmail dot com
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43162
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-02-25 5:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-24 11:30 [Bug c/43162] New: option to set the "promoted" type of parameters of calculus etienne_lorrain at yahoo dot fr
2010-02-24 11:34 ` [Bug c/43162] option to set the "promoted" type of parameters of arithmetic pinskia at gcc dot gnu dot org
2010-02-25 5:13 ` bangerth at gmail dot com
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).