scanf an long long int results problem

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to you scanf for conversion from long long to string char.
I am using unit ATMega16 under the AVRSTudio6
Do you have any idea how fix it ?
Regards
Alwx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I learn someing every day.... I had no idea that there was a long long! gcc doc seems to confirm that there is! http://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html

Are you able to describe the actual problem that you are experiencing? eg doesn't compile, function never returns, returned data is not what you expect....

regards
Greg

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The runtime library does not support 64 bit (long long) conversions for either printf or scanf.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikericetga wrote:
The runtime library does not support 64 bit (long long) conversions for either printf or scanf.
I actually thought 32 bits was the limit but couldn't find a reference saying so....

with a bit more digging if I search for "long long" @ http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#gaa3b98c0d17b35642c0f3e4649092b9f1 I found the statement "this realization does not operate long long arguments." in the vfprintf section.

regards
Greg

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I had no idea that there was a long long!

Far, far better to use int64_t.

@OP I'd suggest a hand implementation of your own atoll(). Set an accumulator to 0. In a loop multiply it by 10 then take each digit in turn - subtract '0' - add to an accumulator and keep looping until non-digit is found.

While this may be over the top as it supports any numeric base. The source of strtol() is here:

http://svn.savannah.nongnu.org/v...

That could be expanded out to use "long long" (though better to call it int64_t) in place of "long".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, thanks.
I have created an own procedure for converting long long to ASCII.
By the way in other cases (like arithmetic operations, type conversions) GCC should work properly with long long int (int64_t) types variables ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

By the way in other cases (like arithmetic operations, type conversions) GCC should work properly with long long int (int64_t) types variables ?

Yup but note that uint64+t + uint64_t can involve 16 of the AVR's 32 registers so it's pretty horrendous - only promote to uint64_t from uint32_t when you absolutely have to.

#include 

volatile uint64_t a, b,c;

__attribute__ ((OS_main)) int main(void) {
	a = b + c;
}

generates:

00000048 
: #include volatile uint64_t a, b,c; __attribute__ ((OS_main)) int main(void) { a = b + c; 48: a0 90 60 00 lds r10, 0x0060 4c: b0 90 61 00 lds r11, 0x0061 50: c0 90 62 00 lds r12, 0x0062 54: d0 90 63 00 lds r13, 0x0063 58: e0 90 64 00 lds r14, 0x0064 5c: f0 90 65 00 lds r15, 0x0065 60: 00 91 66 00 lds r16, 0x0066 64: 10 91 67 00 lds r17, 0x0067 68: 20 91 68 00 lds r18, 0x0068 6c: 30 91 69 00 lds r19, 0x0069 70: 40 91 6a 00 lds r20, 0x006A 74: 50 91 6b 00 lds r21, 0x006B 78: 60 91 6c 00 lds r22, 0x006C 7c: 70 91 6d 00 lds r23, 0x006D 80: 80 91 6e 00 lds r24, 0x006E 84: 90 91 6f 00 lds r25, 0x006F 88: 13 d0 rcall .+38 ; 0xb0 <__adddi3> 8a: 20 93 70 00 sts 0x0070, r18 8e: 30 93 71 00 sts 0x0071, r19 92: 40 93 72 00 sts 0x0072, r20 96: 50 93 73 00 sts 0x0073, r21 9a: 60 93 74 00 sts 0x0074, r22 9e: 70 93 75 00 sts 0x0075, r23 a2: 80 93 76 00 sts 0x0076, r24 a6: 90 93 77 00 sts 0x0077, r25 aa: 80 e0 ldi r24, 0x00 ; 0 ac: 90 e0 ldi r25, 0x00 ; 0 ae: 08 95 ret 000000b0 <__adddi3>: b0: 2a 0d add r18, r10 b2: 3b 1d adc r19, r11 b4: 4c 1d adc r20, r12 b6: 5d 1d adc r21, r13 b8: 6e 1d adc r22, r14 ba: 7f 1d adc r23, r15 bc: 80 1f adc r24, r16 be: 91 1f adc r25, r17 c0: 08 95 ret