public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] Re: sscanf("-1", "%d", &i) fails, returns 0
@ 2002-11-11 14:54 Ray Lee
  2002-11-11 19:09 ` Randy.Dunlap
  0 siblings, 1 reply; 17+ messages in thread
From: Ray Lee @ 2002-11-11 14:54 UTC (permalink / raw)
  To: hps, rddunlap; +Cc: Linux Kernel

> > What should it do?
> I would model this after user space. (Which does strange things: 

<snip>

It only sounds strange at first. It actually means that scanf is
consistent with C's rules of assignment between mixed types. For
example:

ray:~$ cat signs.c

#include <stdio.h>

main() {
	char scan[]="-100";
	unsigned int u;
	int i;

	sscanf(scan, "%ud", &u);
	sscanf(scan, "%d", &i);
	printf("%s scanned to signed %d and unsigned %u\n", scan, i, u);

	i=-100;
	u=i;
	printf("%d assigned to unsigned int gives %u\n", i, u);
}

ray:~$ ./signs
-100 scanned to signed -100 and unsigned 4294967196
-100 assigned to unsigned int gives 4294967196

So, one should think of scanf as having correct knowledge of the types
it's scanning, and then shoe-horning the result into whatever you asked
for. Just like C itself.

Ray


^ permalink raw reply	[flat|nested] 17+ messages in thread
* sscanf("-1", "%d", &i) fails, returns 0
@ 2002-11-08 13:32 Douglas Gilbert
  2002-11-08 19:22 ` [PATCH] " Randy.Dunlap
  0 siblings, 1 reply; 17+ messages in thread
From: Douglas Gilbert @ 2002-11-08 13:32 UTC (permalink / raw)
  To: linux-kernel

In lk 2.5.46-bk3 the expression in the subject line
fails to write into "i" and returns 0. Drop the minus
sign and it works.

Doug Gilbert


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

end of thread, other threads:[~2002-11-14 17:27 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-11 14:54 [PATCH] Re: sscanf("-1", "%d", &i) fails, returns 0 Ray Lee
2002-11-11 19:09 ` Randy.Dunlap
2002-11-11 20:08   ` Andreas Schwab
2002-11-11 20:25   ` Ray Lee
2002-11-13  7:06     ` Randy.Dunlap
2002-11-14 17:34       ` Ray Lee
  -- strict thread matches above, loose matches on Subject: below --
2002-11-08 13:32 Douglas Gilbert
2002-11-08 19:22 ` [PATCH] " Randy.Dunlap
2002-11-08 19:41   ` Richard B. Johnson
2002-11-08 19:59     ` Randy.Dunlap
2002-11-08 20:19       ` Linus Torvalds
2002-11-08 22:09         ` Randy.Dunlap
2002-11-10 13:41           ` Henning P. Schmiedehausen
2002-11-11  3:05             ` Randy.Dunlap
2002-11-11  4:19               ` Randy.Dunlap
2002-11-11  9:27               ` Henning Schmiedehausen
2002-11-11 14:38               ` Andreas Schwab
2002-11-08 20:23       ` Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox