Hi, my program does not do the expected things, printf a unsigned long long int.
#include <aduc7026.h> #include"stdio.h" void RS232_init(void); int main (void) { unsigned long long int A; RS232_init(); printf("Start \n"); while(1) { while(1) { printf("Enter a Hex-number\n"); if (scanf("%X",&A)) break; scanf("%*"); //Clearing scanf input stream } printf ("Your input %64.64lX\n",A); A *= A; printf ("The result %64.64lX\n",A); } } void RS232_init(void) { GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1 // Start setting up UART at 9600bps COMCON0 = 0x080; // Setting DLAB COMDIV0 = 0x088; // Setting DIV0 and DIV1 to DL calculated COMDIV1 = 0x000; COMCON0 = 0x007; // Clearing DLAB }
"Sometimes i think C is the pureness of evil." If you deliberately jumped into a deep pool without first taking the precaution of learning to swim, would it be the pool's fault if you drowned??
"my program does not do the expected things, printf a unsigned long long int." So what do you expect it to do? You've told printf to print a long, but you've actually given it something twice the size!!
printf ("Your input %64.64lX\n",A);
Hi, my program does not do the expected things, Important rule of programming: Programs do what you tell them to do, not what you expect them to do. :)
I just want to force printf to give me unsigned long long integer for example 0x11111111 * 0x11111111 i expect 0x0123456787654321 but the result from printf is only 000000000087654321. What a mess! I'am very very disapointed! Maybe the compiler does not recognize "unsigned long long integer"? But there's no error-message! Who can help?
I just want to force printf to give me unsigned long long integer Then why are you telling printf that the length is long integer (l) instead of long long integer (ll) ?
"Maybe the compiler does not recognize 'unsigned long long integer'?" The compiler recognises it, and the compiler has given you one. However, you have told printf to print a long, and that's exactly what it has done - it has printed a long which is precisely one half of the long long that you supplied! As a programmer with 10 years 8051 assembler experience, you should understand that silly things will happen if you supply inconsistent parameters to a fucntion call! "But there's no error-message!" That's because the program is perfectly valid. That problem is that your program does not actually describe what you want it to do. Again, as a programmer with 10 years 8051 assembler experience, you should realise program execution is a YAFIYGI process: "You Asked For It; You Got It!" You really do need to sit down with a basic 'C' textbook and start with the basics before you go running & jumping into the deep end before you can walk or swim!
sorry i told program to multiply 0x11111111 with 0x111111. The result is 0x0123456787654321. Then i told the program
printf ("The result %16.16LlX\n",(unsigned long long)A);
"what i understand should give me a 16-digit-long-long-Hex-number." And what did it give you?
The CARM compiler does not support printout of long long int values. You should select the RealView Compiler (under Project - Components...). This compiler supports the ANSI C99 extensions. Reinhard
It seems that printf can not print unsigned long long integer with more than 8 Hex-digits. Here is my workaround for printf unsigned long long as hex.
#include <aduc7026.h> #include"stdio.h" void RS232_init(void); void printf_ull_hex(char[],unsigned long long,char[]); int main (void) { unsigned long long A; unsigned char n; RS232_init(); printf("Start\n"); A=1; for(n=0;n<=40;n++) { printf("3^%2.d ",n); printf_ull_hex("= 0x",A,"\n"); A *= 3; } printf("Stop\n"); while(1){} } void printf_ull_hex(char str1[],unsigned long long ull_num,char str2[]) { printf (str1); printf ("%8.8X",ull_num>>32); printf ("%8.8X",ull_num); printf (str2); }
"It seems that printf can not print unsigned long long integer" There is no "seems" about it - you have just been told explicitly by Reinhard Keil himself that The CARM compiler does not support printout of long long int values. Further, you have also been told that the RealView Compiler does support this ANSI C99 extension It only remains to check the GCC manual to see wether or not GCC supports it. (I have a feeling that GCC does support C99...?)
"It only remains to check the GCC manual to see wether or not GCC supports it." Once you can actually find the manual! :-( http://www.keil.com/forum/docs/thread7639.asp Here it is: http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html#Integer-Conversions It says that you can us 'L' (uppercase), 'll' (lowercase), or 'q' to qualify a long long int. Note that a single lowercase 'l' still indicates a long int
Sorry, your' right. See me as someone, who is learning to fly C like the man in the film Those Magnificent Men In Their Flying Machines While he flying, he reads the book "Learning to fly in five lessons" And suddenly the wind brushes the book away... But by the way, what is the difference between all this different compilers? Isn't the Keil-Compiler the best in the world? I can't say, i came to it like the virgin to a child. I just bought this ADuC7026-Eval-Kit. There was a CD... i installed it... and here we are.