Array to integer problem(integer too long).

Victor victor@ambra.ro
Wed Feb 16 16:08:00 GMT 2005


This is very strange - still not working.
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
    long long test;
    test = 89126342536ll;
    printf("Test d : %d  \n", test);
    printf("Test ll: %ll \n", test);
    printf("Test L : %L  \n", test);
    printf("Test q : %q  \n", test);
}

And the result is:
Test d : -1067970680
Test ll: %
Test L : %
Test q : %

I compile lik this:
g++ -L/usr/lib -o test test.cpp
If I try this:
gcc -L/usr/lib -o test test.cpp o receive an error:
/root/tmp/cc668HZr.o(.eh_frame+0x11): undefined reference to 
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Thank you for your patience.

Brian Budge a scris:

>ak, true true.  Add ll to the end of the number.
>
>For example, it would be 89126342536ll (those are Ls not 1s)
>
> Brian
>
>
>On Wed, 16 Feb 2005 13:58:04 +0200, Victor <victor@ambra.ro> wrote:
>  
>
>>I have gcc version 3.4.1 compiled with long long support - but the
>>result is the same.
>>If I try A simple program like this:
>>#include <stdio.h>
>>#include <stdlib.h>
>>int main(int argc, char **argv) {
>>   long long int test;
>>   test = 89126342536;
>>}
>>when I compile I get the following error:
>>test.cpp: In function `int main(int, char**)':
>>test.cpp:14: error: integer constant is too large for "long" type(long
>>long seems to have no effect - it steel refers to simple long for some
>>reason).
>>
>>"gcc -v" output:
>>Reading specs from /usr/lib/gcc/i586-mandrake-linux-gnu/3.4.1/specs
>>Configured with: ../configure --prefix=/usr --libdir=/usr/lib
>>--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info
>>--enable-shared --enable-threads=posix --disable-checking
>>--enable-long-long --enable-__cxa_atexit --enable-clocale=gnu
>>--disable-libunwind-exceptions
>>--enable-languages=c,c++,ada,f77,objc,java
>>--host=i586-mandrake-linux-gnu --with-system-zlib
>>Thread model: posix
>>gcc version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)
>>
>>Brian Budge a scris:
>>
>>    
>>
>>>Ah, okay.  long int in most 32 bit system is the same as int.  Usually
>>>there is a type called long long which is 64 bits on 32 bit systems.
>>>
>>> Brian
>>>
>>>
>>>On Wed, 16 Feb 2005 13:19:05 +0200, Victor <victor@ambra.ro> wrote:
>>>
>>>
>>>      
>>>
>>>>Thank you.
>>>>The problem is that I don't know what type to declare the numeric variable.
>>>>If I try A simple program like this:
>>>>#include <stdio.h>
>>>>#include <stdlib.h>
>>>>int main(int argc, char **argv) {
>>>>   long int test;
>>>>   test = 89126342536;
>>>>}
>>>>when I compile I get the following error:
>>>>test.cpp: In function `int main(int, char**)':
>>>>test.cpp:14: error: integer constant is too large for "long" type
>>>>
>>>>I know I must replace the line "long int test" with something else, but
>>>>I don't know with what.
>>>>Thank you.
>>>>
>>>>Brian Budge a scris:
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Hi Victor -
>>>>>
>>>>>The number you specify is larger than can be held in a 32 bit integer.
>>>>>Use atoll instead.
>>>>>
>>>>>Brian
>>>>>
>>>>>
>>>>>On Wed, 16 Feb 2005 12:53:50 +0200, Victor <victor@ambra.ro> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>>>I have this simple script:
>>>>>>
>>>>>>#include <stdio.h>
>>>>>>#include <stdlib.h>
>>>>>>#include <string.h>
>>>>>>int main(int argc, char **argv) {
>>>>>>  int test;
>>>>>>  char *numar = "89126342536";
>>>>>>  test = atoi(numar);
>>>>>>  printf("Test: %d", test);
>>>>>>}
>>>>>>
>>>>>>I want to convert the string numar to integer.
>>>>>>But the result - when I run the script is :
>>>>>>Test: 2147483647
>>>>>>and I would expect:
>>>>>>Test: 89126342536.
>>>>>>
>>>>>>It seems that the number is too big.
>>>>>>How can I solve this problem.
>>>>>>
>>>>>>Thank you.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>
>>>>>          
>>>>>
>>>>        
>>>>
>>>
>>>      
>>>
>>    
>>
>
>  
>




More information about the Gcc-help mailing list