Bug in warnings

View: New views
4 Messages — Rating Filter:   Alert me  

Bug in warnings

by Rick Jenkins-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Compiling:

static long bug(void)
{
  long bugged;

  bugged = 1 << 30;
  return( bugged );
}

Produces:

msp430-gcc -mmcu=msp430x1611 -pipe -O2 -mendup-at=main -g -minline-hwmul -fno-
defer-pop -I ../include -I ../proc1 -Wall -W -Wcast-align -Wcast-qual -
Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -
Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wswitch -Wunused
-Wwrite-strings -Winline   -c -o bug.o bug.c
bug.c: In function `bug':
bug.c:5: warning: left shift count >= width of type

Using:
> msp430-gcc --version
msp430-gcc (GCC) 3.2.3

compiled from CVS using the makefile in "packaging", as advised in the
documentation.

--
Rick Jenkins <rick@...>
Hartman Technica           http://www.hartmantech.com 
Phone +1 (403) 230-1987
221 35 Avenue. N.E., Calgary, Alberta, Canada T2E 2K5

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@...
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Re: Bug in warnings

by Chris Liechti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why is that a bug? your numbers are ints it does an int calculation an
then extends the result to store it/ return it (the rules when C does
implicit casts are not always intuitive :/ )

if you want to force the compiler to use a different number type than
int (which is 16 bits for the MSP430) you could write 1L << 30

chris

Rick Jenkins schrieb:

> Compiling:
>
> static long bug(void)
> {
>   long bugged;
>
>   bugged = 1 << 30;
>   return( bugged );
> }
>
> Produces:
>
> msp430-gcc -mmcu=msp430x1611 -pipe -O2 -mendup-at=main -g -minline-hwmul -fno-
> defer-pop -I ../include -I ../proc1 -Wall -W -Wcast-align -Wcast-qual -
> Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -
> Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wswitch -Wunused
> -Wwrite-strings -Winline   -c -o bug.o bug.c
> bug.c: In function `bug':
> bug.c:5: warning: left shift count >= width of type
>
> Using:
>> msp430-gcc --version
> msp430-gcc (GCC) 3.2.3
>
> compiled from CVS using the makefile in "packaging", as advised in the
> documentation.
>


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@...
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Parent Message unknown Re: Bug in warnings

by Rick Jenkins-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 09 November 2009 10:28  Chris Liechti wrote:
> Why is that a bug? your numbers are ints it does an int calculation an
> then extends the result to store it/ return it (the rules when C does
> implicit casts are not always intuitive :/ )

My apologies, you are of course correct. In fact, best practice would be:

#include <sys/inttypes.h>
static int32_t bugfree(void)
{
  int32_t debugged;

  debugged = (int32_t)1 << 30;
  return( debugged );
}

This is almost portable, but for the fact that inttypes.h is in sys on
msp430gcc. Is there any compelling reason for this?
--
Rick Jenkins <rick@...>
Hartman Technica           http://www.hartmantech.com 
Phone +1 (403) 230-1987
221 35 Avenue. N.E., Calgary, Alberta, Canada T2E 2K5

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@...
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Parent Message unknown Re: Bug in warnings

by JMGross :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


stdlib.h includes sys/types.h which itself includes sys/inttypes.h
I guess it has been moved there along with other relocations of include files in the linux/gcc world.
And it makes some sense. the definitions of the various INT types are system specific (this is why you need this file at all). The main include folder should only contain include files which are identical for all systems.
Of course it makes not too much sense if the whole system setup is focused on only one target (the MSP430). And all the msp430x.h files are misplaced too.

JMGross

p.s.: you can use '1L' instead of '(int32_t)1' in case of long constants.

----- Ursprüngliche Nachricht -----
Von: Rick Jenkins
An: mspgcc-users@...
Gesendet am: 09 Nov 2009 18:52:52
Betreff: Re: [Mspgcc-users] Bug in warnings

On Monday 09 November 2009 10:28  Chris Liechti wrote:
> Why is that a bug? your numbers are ints it does an int calculation an
> then extends the result to store it/ return it (the rules when C does
> implicit casts are not always intuitive :/ )

My apologies, you are of course correct. In fact, best practice would be:

#include <sys/inttypes.h>
static int32_t bugfree(void)
{
  int32_t debugged;

  debugged = (int32_t)1 << 30;
  return( debugged );
}

This is almost portable, but for the fact that inttypes.h is in sys on
msp430gcc. Is there any compelling reason for this?


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@...
https://lists.sourceforge.net/lists/listinfo/mspgcc-users