This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: code questions.


Scott,

I just tried the following:

a = (unsigned short) ( a + 1 ) % b;

which appears to work as you expect. I tried it using gcc 3.4.4 on Windows (Cygwin).

Good luck!

--
Tony Wetmore
Raytheon Solipsys


Scott Phuong wrote:
I see. Well, thank you very much for your help. I appreciate the quick response.

Scott

On Mon, Jun 2, 2008 at 7:11 PM, me22 <me22.ca@gmail.com> wrote:
On Mon, Jun 2, 2008 at 10:04 PM, Scott Phuong <mycleanjunk@gmail.com> wrote:
Thanks so much for your quick reply. This code is simliar to code in a
third party source code that I have to fix and they do this all over
the place. The question is w/o touching their code is there a way I
can fix this?
Switch to a platform with 16-bit ints?

I tried explicitly casting the 1 to an unsigned short
but it doesn't seem to work like this:

a = (a + (unsigned short) 1) % b.

More evidence that you're hitting integral promotion, so there's
basically nothing you can do about it.

(Besides make sure a is never that large :P)





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]