From: lordbah@amusing.Bah.Rochester.NY.US (Jeff Van Epps)
Newsgroups: comp.sys.amiga.programmer
Subject: SAS C 5.10 bug?
Followup-To: comp.sys.amiga.programmer
Distribution: world
Reply-To: lordbah@amusing.Bah.Rochester.NY.US
Date: 1 Jan 93 09:08:07 EDT
Organization: Bah's News Club

OK, here's that problem I mentioned earlier.  It compiled OK with the
optimizer while I was running AmigaDOS 1.3, but fails now with 2.1.
At least I firmly believe that it was OK under 1.3, but I can't/won't
downgrade the machine to check it out now.

====== code here ======

# include	<stdio.h>

# define	MAX_VARS			20
# define	MAX_NAME_LEN		10
# define	MAX_VALUE_LEN		80

static struct {
	char		name[MAX_NAME_LEN+1];		/* name of variable */
	char		value[MAX_VALUE_LEN+1];		/* its value */
	} vars[MAX_VARS];

static int	n_vars = 0;

main()
{
int i;
char tmp[10];

n_vars = 10;
for(i=0;i<n_vars;i++)
	{
	sprintf( tmp, "name%d", i );
	strcpy( vars[i].name, tmp );
	sprintf( tmp, "value%d", i );
	strcpy( vars[i].value, tmp );
	}
for(i=0;i<n_vars;i++)
	printf("vars[%d].name '%s' value '%s'\n",i,vars[i].name,vars[i].value);
}

====== end of code ======
====== compile & run ====

[WB:Communications/UUCP.old/src/AmigaNews/Anews/ARN]: lc -L -O testme
SAS/C Compiler V5.10 for AmigaDOS
Copyright (C) 1990 SAS Institute, Inc. All Rights Reserved.

Compiling testme.c
Optimizing
Module size P=00000080 D=00000033 U=00000730

Total files: 1, Compiled OK: 1
Linking testme
Blink - Version 5.10
Copyright (c) 1990 SAS Institute, Inc.  All Rights Reserved.


BLINK Complete - Maximum code size = 9204 ($000023f4) bytes

Final output file size = 7088 ($00001bb0) bytes
[WB:Communications/UUCP.old/src/AmigaNews/Anews/ARN]: testme
vars[0].name 'name9' value 'value9'
vars[1].name 'name9' value 'value9'
vars[2].name 'name9' value 'value9'
vars[3].name 'name9' value 'value9'
vars[4].name 'name9' value 'value9'
vars[5].name 'name9' value 'value9'
vars[6].name 'name9' value 'value9'
vars[7].name 'name9' value 'value9'
vars[8].name 'name9' value 'value9'
vars[9].name 'name9' value 'value9'
[WB:Communications/UUCP.old/src/AmigaNews/Anews/ARN]:

===== end of run =====

Now, I can't see anything wrong with this code, especially since it
works fine without the optimizer.  I would guess that for some reason
the optimizer can't see that the loop var is being referenced inside
the loop.  This test program uses printf, the 'real' code I was working
on uses strcmp inside the loop.  Perhaps the fact that these can both
be "builtin" functions has something to do with it?  [But maybe not,
I just recompiled with an #undef printf and got the same results.]

[For the curious: this is part of the BARN newsreader, *not* the ARN
newsreader, despite the fact that I never changed the directory name
when I changed the name of the program.]

BTW, this is cute.  I received the 6.0 upgrade offer on 12/29, and it
says the pricing is valid until 12/31.  I called SAS and they were
closed until 1/4.  So I tried to mail in the order, but someone/thing
knocked over my mailbox so the mailman didn't pick up the outgoing
mail, thus my order won't be postmarked until 1/2.  I guess I'll have
to appeal to SAS when I get the bill :-]

--------------------------------------------------------------------
    Jeff Van Epps    uunet!amusing!lordbah
                     lordbah@amusing.Bah.Rochester.NY.US
Newsgroups: comp.sys.amiga.programmer