Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

How can I get rid of "Warning C4307: integral constant overflow"


Microsoft Visual Studio 2005 Version 8.0.50727.762  (SP.050727-7600)

How do I get rid of "Warning C4307: '-' : integral constant overflow" from
the following macro?
    #define d_ReturnMax(I_iTypeSize)\
    (    (int64(1)<<((I_iTypeSize*8)-1))-1)

There NO warnings when done as a function:
    int64 d_ReturnMax(int64 I_iTypeSize)
    {    return (1<<((I_iTypeSize*8)-1))-1;}

Test code:
    int64 L_iMaxIntSize=d_ReturnMax(sizeof(int32));    //
L_iMaxIntSize=0x000000007fffffff
    int64 L_iMaxIntSize=d_ReturnMax(sizeof(char));    //
L_iMaxIntSize=0x000000000000007f

I tried typecasting around all parts of code i.e. int64(...)/(int64)... I
give up now.
Can anyone else spot something I have missed?

--
From _Christopher (M2M).
RefCode:44CdccTCDf42 V04
void DeadEnds() {for(;;);}      //    :)

If replying by email please included ##71; on the subject line followed by
your subject, any post without the ##71; tag WILL be deleted.  I.e.   "##71;
Thank for the help."

Probably.  One, 'int64' is compiler-specific and should be asked
about in the newsgroup dedicated to that compiler.  Two, to form
a constant of a particular type you need to follow it with a certain
suffix, like 0xffL for 'long' or 0x55U for 'unsigned' (hint: int64
probably has its own dedicated suffix), do not use a "cast".  Also,
shifts only work with the right argument between 0 and some
(relatively small) number.  Make sure whatever '((I_iTypeSize*8)-1))'
(do you really need all those parentheses?) expands into is between
0 and the maximum allowed value (63?).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

On Jun 5, 10:49 pm, "Victor Bazarov" <v.Abaza@comAcast.net> wrote:

int64_t is part of C99, and is in the current draft.  It's
pretty obvious, I think, what int64 is supposed to be.

> Two, to form
> a constant of a particular type you need to follow it with a certain
> suffix, like 0xffL for 'long' or 0x55U for 'unsigned' (hint: int64
> probably has its own dedicated suffix), do not use a "cast".

There's no problem using a cast as long as the value is in fact
representable as an int.  In his case, the value is 1, so
there's no problem.  In many cases, the cast is necessary,
because you don't know the actual type involved, e.g. if dealing
with size_t.

> Also,
> shifts only work with the right argument between 0 and some
> (relatively small) number.
> Make sure whatever '((I_iTypeSize*8)-1))'
> (do you really need all those parentheses?) expands into is between
> 0 and the maximum allowed value (63?).

In his test code, the conditions are met.  Or at least they are
if int64 really is a 64 bit int; the only explination I can see
is that the compiler is evaluating the integral constant
expression as a 32 bit long, despite the presence of an int64 in
it.  (Perhaps this part of the compiler hasn't been reworked to
reflect the presence of the new integral types.)  At any rate,
there is no overflow in his expression.

--
James Kanze (GABI Software)             email:james.ka@gmail.com
Conseils en informatique oriente objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

"James Kanze" <james.ka@gmail.com> wrote in message

news:1181120606.219631.126440@k79g2000hse.googlegroups.com...
On Jun 5, 10:49 pm, "Victor Bazarov" <v.Abaza@comAcast.net> wrote:

int64_t is part of C99, and is in the current draft.  It's
pretty obvious, I think, what int64 is supposed to be.

> Two, to form
> a constant of a particular type you need to follow it with a certain
> suffix, like 0xffL for 'long' or 0x55U for 'unsigned' (hint: int64
> probably has its own dedicated suffix), do not use a "cast".

There's no problem using a cast as long as the value is in fact
representable as an int.  In his case, the value is 1, so
there's no problem.  In many cases, the cast is necessary,
because you don't know the actual type involved, e.g. if dealing
with size_t.

> Also,
> shifts only work with the right argument between 0 and some
> (relatively small) number.
> Make sure whatever '((I_iTypeSize*8)-1))'
> (do you really need all those parentheses?) expands into is between
> 0 and the maximum allowed value (63?).

In his test code, the conditions are met.  Or at least they are
if int64 really is a 64 bit int; the only explination I can see
is that the compiler is evaluating the integral constant
expression as a 32 bit long, despite the presence of an int64 in
it.  (Perhaps this part of the compiler hasn't been reworked to
reflect the presence of the new integral types.)  At any rate,
there is no overflow in his expression.

--
James Kanze (GABI Software)             email:james.ka@gmail.com
Conseils en informatique oriente objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

---------8<--------

> Probably.  One, 'int64' is compiler-specific and should be asked
> about in the newsgroup dedicated to that compiler.

Sorry about not making it clear about the int64
typedef __int64 int64;

And yes you're right I repost it to:
microsoft.public.vc.language

Thanks anyway.
--
From _Christopher (M2M).
RefCode:444CdcTCDcl4 V04
void DeadEnds() {for(;;);}      //    :)

If replying by email please included ##71; on the subject line followed by
your subject, any post without the ##71; tag WILL be deleted.  I.e.   "##71;
Thank for the help."

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc