[mod.computers.vax] Potential C problem

bobp@tektools.tek.CSNET.UUCP (06/26/86)

	Perhaps I missed something in the documentation, but can anyone
tell me why the VMS C compiler doesn't allow a value of 0 in %x1 as in the
following example ?

-------------------------------------------------------------------
$! c sscanf/fscanf %x1 bug
$cre bug.c
#include <stdio.h>
main()
{
    int c;
    int d;

    c=getc(stdin);
    if (sscanf(&c,"%x1",&d) == 0)
       printf("not a hex character\n");
    else
       printf("hex character = %d\n",d);
}
$
$cc bug
$link bug,sys$library:vaxcrtl/lib
$run bug
1
$run bug
f
$run bug
0
$

----------------------------------------------------------

-- 
Robert N. Perry (Bob)
Tektronix, Inc. 

tektronix!tektools!bobp
bobp%tektools@tektronix
bobp%tektools@tektronix.csnet-relay
bobp%tektools%tektronix@csnet-relay

"When I works, I works hard. When I sits, I sits easy. When I thinks, I goes
to sleep."

LEICHTER-JERRY@YALE.ARPA.UUCP (07/01/86)

    	Perhaps I missed something in the documentation, but can anyone
    tell me why the VMS C compiler doesn't allow a value of 0 in %x1 as in the
    following example ?

	[example omitted]

    Robert N. Perry (Bob)
Known bug; I believe it's fixed in VAX C V2.2.
    							-- Jerry
-------

m1b.UUCP@rayssd.UUCP (M. Joseph Barone) (07/01/86)

In article <8606261652.AA25082@tektools.TEK>, bobp@tektools.tek.CSNET
(Robert Perry) writes:
> 	Perhaps I missed something in the documentation, but can anyone
> tell me why the VMS C compiler doesn't allow a value of 0 in %x1 as in the
> following example ?
> [example follows using sscanf]

This is a real problem and has been SPRed (SPR NO. 11-CS01837).
The response DEC sent us follows:

	A change is made in VAX C RTL fscanf function (V2.1) to support
	"0x" input string and therefore incidentally ignores leading
	zeros if fscanf function is reading with a "%x" input format
	specifier.

	This problem will be fixed in a future release of VAX C RTL that
	will be shipped with a future version of VAX/VMS after VAX/VMS
	V4.2.  The change made for supporting "0x" input string will also
	be documented in the next edition of "Programming in VAX C".

	The workaround is to enter either a leading "0x" or a leading "0"
	to get the value 0 matched as you have indicated in your SPR.

We're still at V4.2 and when I looked through the V4.3 kit, I didn't find
any patches to VAXCRTL.OLB.  I don't know if this has truly been corrected
in V4.4.

Joe Barone
{allegra, cci632, gatech, ihnp4, linus, mirror, raybed2}!rayssd!m1b
Raytheon Co, Submarine Signal Div., 1847 West Main Rd, Portsmouth, RI 02871

carl@CITHEX.CALTECH.EDU.UUCP (07/04/86)

The problem is that sscanf is stripping leading zero's. When that's all
you've got, it fails.  By the way, I suspect you wanted to use the string
"%1x" rather than "%x1" in your example, though both have the same problem.

carl@CITHEX.CALTECH.EDU.UUCP (07/04/86)

Known bug; I believe it's fixed in VAX C V2.2.
The bug involving sscanf's not recognizing a 0 as a hex digit is still in
VAX-C V2.2-015.  It is the result of scanf's strategy for dealing with
integer conversions, in which it "optimizes" by skipping leading zero's.
To merely state that it's a "known bug" is of little help to somebody trying
to work around it.  You need either to list all cases in which the bug
occurs or give a description of what the problem REALLY is.

LEICHTER-JERRY@YALE.ARPA (07/08/86)

    > Known bug; I believe it's fixed in VAX C V2.2.

    The bug involving sscanf's not recognizing a 0 as a hex digit is still in
    VAX-C V2.2-015.  It is the result of scanf's strategy for dealing with
    integer conversions, in which it "optimizes" by skipping leading zero's.
    To merely state that it's a "known bug" is of little help to somebody
    trying to work around it.  You need either to list all cases in which the
    bug occurs or give a description of what the problem REALLY is.

All I knew about the bug was what I said:  That it had been reported before.
I didn't know the origin, nor did I have any direct way to check that it WAS
fixed in 2.2, only that it WASN'T fixed in 2.1, the latest version installed
here.  Because of the timing of the reports, I'm surprised that it wasn't
fixed in VAX C V2.2.  On the other hand, this is a problem in VAXCRTL, which
is no longer shipped with the VAX C kit, but directly with VMS.  So the right
answer might be "fixed in VMS V4.4" (which we don't have installed yet
either....))

You are certainly welcome to provide more information if you have it.  I
posted my message to (perhaps) save people unnecessary time staring at their
programs and the documentation, trying to figure out what THEY had done wrong.

							-- Jerry
-------

Joe@WASHINGTON.ARPA.UUCP (07/08/86)

Starting with VAX C V2.2-015, the CRTL is not shipped with compiler
updates.  This means that installing version 2.2 will not fix any
outstanding runtime library bugs.  These bugs are fixed in VMS releases.

To answer another question, VMS V4.4 does fix the sscanf problem in the
C runtime library.  This fix is totally independint of whether you
are running version 2.1 or 2.2 of VAX C (assuming that you don't try
to reinstall version 2.1 after upgrading to VMS 4.4.....)

/Joe
-------