problem abt printf on Turboc

E

Eltee

Mark said:
You have added exactly zero to this thread, apart from fuckwittedness.

No, that's your contribution.
> If
you must fiddle with your plonker please do it in private, nobody here
thinks its big or clever.

I'm not after your (or anybody elses) opinion. I'm not trying to look clever either.
 
K

Keith Thompson

Eltee said:
I'm not after your (or anybody elses) opinion. I'm not trying to
look clever either.

Then what on Earth *are* you trying to do? Are you just trolling, or
is there more to it than that?
 
E

Eltee

Keith said:
Then what on Earth *are* you trying to do? Are you just trolling, or
is there more to it than that?

Just trolling, yes. I'm a sinner, I admit. The flesh is weak what can I say. >:)E)

I was taken a back reading the first few replies to my original post (and all
the "lectures" why I deserved them). Reading some other posts which, by the same
standards, should be dismissed like mine but weren't, I concluded that the
"wisemen" of this NG are trying to patronize a newcomer like me. As I don't like
to be patronized I guess I succumbed to the overpowering appeal of vengeance ;-)
and posted some stuff that shouldn't be posted.

Does that qualify as "more to it"?
 
E

Emmanuel Delahaye

1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
7 clrscr();
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig= %lld and not %ld\n", verybig, verybig);
12 getch();
13 return 0;
14 }

Turbo C is a 16-bit C90 compiler.

You should work harder on the types you passed to printf(). They must
match. The cast is not a option.

#include <stdio.h>
#define C99 0

int main (void)
{
unsigned long un = 3000000000UL;
short end = 200; /* and 16-bit short */
unsigned int big = 6553;

#if C99
/* not supported by C90 */
long long verybig = 12345678908642;
#endif

printf ("un = %u and not %d\n", (unsigned) un, (int) un);
printf ("end = %hd and %d\n", (short) end, (int) end);
printf ("big = %ld and not %d\n", (long) big, (int) big); /*this
one */
#if C99
/* not supported by C90 */
printf ("verybig= %lld and not %ld\n", (long long) verybig, (long)
verybig);
#endif

puts ("Press <enter> to quit");
(void) getchar ();
return 0;
}

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
 
D

Dietmar Schindler

for the below code I worked on the Turboc
the result I was expecting was different from what has been printed I
have indicated the line with " /*this one*/" line no 10
I did expected some junk for the first %ld and 6553 for the second %d
,but it printed in different way I am also pasting the result printed ,
it is below the code .
...
/*code */

1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
7 clrscr();
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig= %lld and not %ld\n", verybig, verybig);
12 getch();
13 return 0;
14 }

the Output is below

un = 24064 and not 24064
end = 200 and 200
big = 429463961 and not 996 /* <-why it is 996 whynot 6553*/
verybig= 1942899938 and not 1942899938

Your assumption "system with 32-bit int" is erroneous. Your compilation
system uses 16-bit (unsigned) int.
 
K

Keith Thompson

Eltee said:
Just trolling, yes. I'm a sinner, I admit. The flesh is weak what can I say. >:)E)

I was taken a back reading the first few replies to my original post
(and all the "lectures" why I deserved them). Reading some other posts
which, by the same standards, should be dismissed like mine but
weren't, I concluded that the "wisemen" of this NG are trying to
patronize a newcomer like me. As I don't like to be patronized I guess
I succumbed to the overpowering appeal of vengeance ;-)
and posted some stuff that shouldn't be posted.

Does that qualify as "more to it"?

Not really. My advice is to post a brief followup saying that you
intend to stop trolling, and then actually stop trolling. (The first
part is optional, I suppose.) Or you can just go away. If you have
something to say about C, you're welcome here. Unfortunately you're
probably already in a lot of the regulars' killfiles, so your
opportunities for participation are limited.

And if you think I'm being patronizing, well that's just too bad.
 
O

Old Wolf

1 int main(void)
2 {
3 unsigned int un = 3000000000; /* system with 32-bit int */
4 short end = 200; /* and 16-bit short */
5 unsigned int big = 6553;
6 long long verybig = 12345678908642;
7 clrscr();
8 printf("un = %u and not %d\n", un, un);
9 printf("end = %hd and %d\n", end, end);
10 printf("big = %ld and not %d\n", big,big); /*this one */
11 printf("verybig= %lld and not %ld\n", verybig, verybig);
12 getch();
13 return 0;
14 }
big = 429463961 and not 996 /* <-why it is 996 whynot 6553*/

(Note, the following is all specific to your system. In
general you caused undefined behaviour by using the wrong
specifiers for printf).

You are on a 16-bit system. You passed 2 16-bit parameters to
the variadic function printf: 0x1999 0x1999. printf sees "%ld"
so it reads 32 bits from its parameters: 0x19991999 , which
is 429463961 in decimal. Then it sees "%d" so it reads 16
more bits from the list (and gets garbage).
If you wrote: printf("%ld %d\n", big, big, big) you would
probably see 429463961 6553.

If you don't believe that you're on a 16 bit system:
#include <limits.h>
......
printf("int is %d bits\n", (int) (sizeof(int) * CHAR_BIT) );
 
M

Mark McIntyre

But "we" can't ignore a couple of fns in my (quasi?)C code I posted not long
ago? Hm.

Unlike the question in this thread, your question was itself offtopic. If
you can't discern the difference, you need a better brain.
Just about every != every.

Feel free to grasp at the tiny straws.
 
M

Mark McIntyre

Hi Mark


thats what i actually wanted because i am not changing any thing there
i m just printing it in decimal and the number is also in the limits ie
(-32767 - +3768)

You lied to the compiler - you told it (for example) the value was an int
when it was a long int, and so it will have grabbed the wrong number of
bits.
.Do you mean to say any "ENDIAN" problem here

This is precisely the detail thats offtopic. You'd need to ask in a borland
group as frankly I have no idea how borland's compiler processes data that
overflows the allowed space. It may be to do with which end of the set of
bits the compiler interpreted as an int, or it may not.
 
M

Mark McIntyre

Keith said:
[...]
Then what on Earth *are* you trying to do? Are you just trolling, or
is there more to it than that?

standards, should be dismissed like mine but weren't, I concluded that the
"wisemen" of this NG are trying to patronize a newcomer like me. As I don't like
to be patronized I guess I succumbed to the overpowering appeal of vengeance ;-)

Then you're a complete idiot. Grow up, stop being such a baby.

*plonk*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top