public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* do I need to report this in the bug list?
@ 2004-01-20 11:34 Sridhar
  2004-01-20 12:47 ` John Love-Jensen
  2004-01-20 14:34 ` Felix Lee
  0 siblings, 2 replies; 3+ messages in thread
From: Sridhar @ 2004-01-20 11:34 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

#include <stdio.h>

int
main(int ac, char **av)
{
    unsigned short int a;
    unsigned short int b;

    printf("Enter a: ");
    scanf("%d", &a);
    printf("a = %d\n\n", a);

    printf("Enter b: ");
    scanf("%d", &b);

    printf("a = %d\n", a);
    printf("b = %d\n", b);
}

Output of the program:
Enter a: 12
a = 12

Enter b: 53
a = 0
b = 53

My problem is that a, becomes zero after the scanf operation of b. And when
I tried to use %h instead of %d the program did even stop for the inputs. I
can avoid the zeroing of if and i declare another short variable between a &
b.

is there any compiler option that I need to enable for compiling this
rightly.

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: do I need to report this in the bug list?
  2004-01-20 11:34 do I need to report this in the bug list? Sridhar
@ 2004-01-20 12:47 ` John Love-Jensen
  2004-01-20 14:34 ` Felix Lee
  1 sibling, 0 replies; 3+ messages in thread
From: John Love-Jensen @ 2004-01-20 12:47 UTC (permalink / raw)
  To: Sridhar, 'gcc-help@gcc.gnu.org'

Hi Sridhar,

It's not a bug.  Your code is bad.

An "unsigned short int" is not the same as an "int".

You are performing a scanf for an int ("%d"), but you are storing it in an
unsigned short int.  Bad voodoo.

--Eljay


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: do I need to report this in the bug list?
  2004-01-20 11:34 do I need to report this in the bug list? Sridhar
  2004-01-20 12:47 ` John Love-Jensen
@ 2004-01-20 14:34 ` Felix Lee
  1 sibling, 0 replies; 3+ messages in thread
From: Felix Lee @ 2004-01-20 14:34 UTC (permalink / raw)
  To: Sridhar; +Cc: 'gcc-help@gcc.gnu.org'

Sridhar <asridhar@ishoni.com>:
> My problem is that a, becomes zero after the scanf operation of b. And when
> I tried to use %h instead of %d the program did even stop for the inputs. I

%h is a modifier.  you need to say "%hd".

actually, you should say "%hu" since you're using unsigned short ints.
--

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-01-20 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-20 11:34 do I need to report this in the bug list? Sridhar
2004-01-20 12:47 ` John Love-Jensen
2004-01-20 14:34 ` Felix Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).