This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: constant expression bug in gcc
- From: Graham Stott <grahams at redhat dot com>
- To: Peter Selinger <selinger at mathstat dot uottawa dot ca>
- Cc: bug-gcc at gnu dot org
- Date: Fri, 30 Nov 2001 07:39:59 -0500
- Subject: Re: constant expression bug in gcc
- References: <200111301208.fAUC81R02782@quasar.mathstat.uottawa.ca>
[Get raw message]
Peter,
Peter Selinger wrote:
>
> There is an apparent bug in constant expression evaluation in gcc 2.96.
>
> Here is a program:
>
> #include <stdio.h>
>
> int main() {
> printf("%d\n", sizeof(unsigned long)-5 );
> printf("%d\n", (sizeof(unsigned long)-5) >= 0 ? 1 : -1);
> }
>
> Here is its output:
>
> % ./test
> -1
> 1
> % uname -a
> Linux caiaphas 2.2.19-7.0.8 #1 Thu Jun 21 04:59:33 EDT 2001 i686 unknown
> % gcc --version
> 2.96
>
> Please let me know if you need more information.
> Thanks, -- Peter
No more info needed. It is not a bug.
sizeof returns an unsigned integral type (size_t) so the expression
"sizeof (unsigned long) - 5" is itself unsigned, hence the output you
quoted is correct.
Graham