gcc 2.95.2-151 / 32-bit integers

John Ruff jruff@nc.rr.com
Sat Jun 2 19:24:00 GMT 2001


Tim:

Thanks for your reply.  And I understand that g++ is just a script that 
calls gcc with options necessary to compile C++ code.  But the fact that 
a int (32-bit) takes up 4 bytes of memory and can hold a numeric value 
between -2,147,483,648 to 2,147,483,647 is a rule of standard machine 
language.  An unsigned int (32-bit) still uses 4 bytes of memory and can 
hold a numeric from 0 to 4,294,967,295.  And if the value of int 
overflows that buffer the C/C++ compiler handles it by wrapping around.  
This works with gcc 2.95.2 when compiling C source code but not C++ 
source code.  And both C/C++ compile this code correctly when using gcc 
2.8.1.  Try it yourself.

Example C source code:
/*---------test.c---------------------*/
#include <stdio.h>

void main()
{
  int number;
  number = 9999999999;
  printf ("The integer number= %d\n", number);
  return 0;     
}
/*-----------end--------------------*/

Regards,

John Ruff


Tim Prince wrote:

If you want defined wrap-around behavior you must employ casts to make
sure everything is done unsigned.  gcc is intended to be a C compiler.

> ----- Original Message -----
> From: "John Ruff" <jruff@nc.rr.com> < mailto:jruff@nc.rr.com >
> To: <gcc-bugs@gcc.gnu.org> < mailto:gcc-bugs@gcc.gnu.org >
> Sent: Saturday, June 02, 2001 4:46 PM
> Subject: gcc 2.95.2-151 / 32-bit integers
> 
> 
>> GNU:
>> 
>> I understand that when compliing C++ source code where a 'int' has
> 
> been
> 
>> defined and that integer's variable has been giving a value greater
> 
> than
> 
>> (+/-)2,147,483,647 such as 9,999,999,999 then that value should be
>> wrapped around and equal 1,410,065,407.  This works with gcc-2.8.1,
> 
> and
> 
>> when complied produces only a warning.  However, when complied with
>> gcc-2.95.2, an error is produced and the compilation aborts abnormally
>> with an exit status 1.
>> 
>> System Info:
>> Linux 2.2.18 / gcc 2.95.2-151
>> 
>> Below is a simple example:
>> 
>> //-------------------test.cpp---------------
>> #include <iostream.h>
>> 
>> void main()
>> {
>>   int number;
>>   number = 9999999999;
>>   cout << "The integer number= " << number << endl;
>> }
>> //------------------end-------------------
>> 
>> If there is a patch or newer version I should install please let me
> 
> know.
> 
>> 
>> Thanks in advance,
>> 
>> John Ruff
>> jruff@nc.rr.com < mailto:jruff@nc.rr.com >
>> 
> 
> 
> 




More information about the Gcc-bugs mailing list