[comp.std.c] scanf %x allows leading 0x?!?

scjones@thor.sdrc.com (Larry Jones) (05/10/91)

I was just surprised to discover that the %x conversion specifier
used in the *scanf functions allows the target string to have a
leading 0x or 0X.  I don't remember any discussion about it and a
few quick tests show about a 50/50 split of systems that allow it
and systems that don't.  Was that behavior specified in the SVID
or /usr/group specs, was it picked up from somewhere else, or is
it just an unaticipated feature?
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
Domain: scjones@sdrc.com             Path: uunet!sdrc!scjones
Rats.  I can't tell my gum from my Silly Putty. -- Calvin

steve@taumet.com (Stephen Clamage) (05/12/91)

scjones@thor.sdrc.com (Larry Jones) writes:

|I was just surprised to discover that the %x conversion specifier
|used in the *scanf functions allows the target string to have a
|leading 0x or 0X.  I don't remember any discussion about it and a
|few quick tests show about a 50/50 split of systems that allow it
|and systems that don't.  Was that behavior specified in the SVID
|or /usr/group specs, was it picked up from somewhere else, or is
|it just an unaticipated feature?

It is the explicitly-specified behavior in ANSI C.  On systems which
do not follow the ANSI standard, you may get different behavior.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com

gwyn@smoke.brl.mil (Doug Gwyn) (05/12/91)

In article <725@taumet.com> steve@taumet.com (Stephen Clamage) writes:
>It is the explicitly-specified behavior in ANSI C.  On systems which
>do not follow the ANSI standard, you may get different behavior.

Larry knows that, he just didn't remember voting on it.
I recall (vaguely) that it was a deliberate decision.

peter@ficc.ferranti.com (Peter da Silva) (05/14/91)

In article <725@taumet.com> steve@taumet.com (Stephen Clamage) writes:
> scjones@thor.sdrc.com (Larry Jones) writes:
> |I was just surprised to discover that the %x conversion specifier
> |used in the *scanf functions allows the target string to have a
> |leading 0x or 0X.

> It is the explicitly-specified behavior in ANSI C.  On systems which
> do not follow the ANSI standard, you may get different behavior.

OK, whose bright idea was this? I know scanf is pretty much a loss in general,
but doesn't this further dilute its reliability?

Given:
	scanf("%x%c", &integer, &byte);

With the input
	4300ay
	0 b
	0cx
	0x

Is this supposed to fail on the final example, or succeed?
-- 
Peter da Silva; Ferranti International Controls Corporation; +1 713 274 5180;
Sugar Land, TX  77487-5012;         `-_-' "Have you hugged your wolf, today?"