Thread View: comp.bugs.sys5
6 messages
6 total messages
Started by Dean Long
Thu, 25 Dec 1986 23:23
chars in conditional expression, 3b2 C compiler
Author: Dean Long
Date: Thu, 25 Dec 1986 23:23
Date: Thu, 25 Dec 1986 23:23
23 lines
1079 bytes
1079 bytes
Try these two commands on a 3b2 running SYSV unix on the following program:
cc -c sub.c # should work OK
cc -DCRASH -c sub.c # /lib/ccom should core dump
Does anyone have any ideas?
----------------------------------------------------------------------
sub()
{
char x;
int i;
i = ((x > 0) ? 1 : 0);
i = ((x >= 1) ? 1 : 0);
#ifdef CRASH
i = ((x >= 0) ? 1 : 0);
#endif
}
--
Dean Long
San Diego State Univ.
sdcsvax!sdsu!dlong
Re: chars in conditional expression, 3b2 C compiler
Author: Kim Chr. Madsen
Date: Tue, 30 Dec 1986 23:00
Date: Tue, 30 Dec 1986 23:00
22 lines
1176 bytes
1176 bytes
In article <2489@sdsu.UUCP>, dlong@sdsu.UUCP (Dean Long) writes: > Try these two commands on a 3b2 running SYSV unix on the following program: > > cc -c sub.c # should work OK > cc -DCRASH -c sub.c # /lib/ccom should core dump > > [some code].... Well, tried this one out without any problems on this 3b2 running UNIX System V R2.1 are you running Release 3 or an older (pre 2.1 release) system V. The only thing that really bugs me is the fact that chars are unsigned and therefore the following code will fail: while ((c=getc(stream)) != EOF) putchar(c); And you will have to redefine EOF to 255 (0377 or 0xff) or cast it to a char! Kim Chr. Madsen
Re: chars in conditional expression, 3b2 C compiler (Now stdio)
Author: Jim Webb
Date: Fri, 02 Jan 1987 01:07
Date: Fri, 02 Jan 1987 01:07
12 lines
1050 bytes
1050 bytes
> The only thing that really bugs me is the fact that chars are unsigned
> and therefore the following code will fail:
>
> while ((c=getc(stream)) != EOF) putchar(c);
>
> And you will have to redefine EOF to 255 (0377 or 0xff) or cast it to a char!
Ummm. I always declare c as an int, not a char, and everything works fine
and dandy...
--
Jim Webb "Out of phase--get help" ...!ihnp4!hropus!jrw
"Make sure comments and code agree. If not, write a man page..."
Re: chars in conditional expression, 3b2 C compiler
Author: James Van Artsdalen
Date: Fri, 02 Jan 1987 11:19
Date: Fri, 02 Jan 1987 11:19
18 lines
1542 bytes
1542 bytes
IN article <189@olamb.UUCP>, kimcm@olamb.UUCP (Kim Chr. Madsen) wrote: > The only thing that really bugs me is the fact that chars are unsigned > and therefore the following code will fail: > > while ((c=getc(stream)) != EOF) putchar(c); > > And you will have to redefine EOF to 255 (0377 or 0xff) or cast it to a char! This code will fail no matter how chars are handled, assuming "c" is a "char". If you remember that getc() returns an *int*, not a char, and have "int c" instead of "char c", this works just fine. If "c" is declared "char c;", the while loop above is broken even with signed chars: what happens to the while loop if a 0xff is in the file? It terminates early, whereas if c is "int c;" is works OK. lint will find this kind of bug. -- James R. Van Artsdalen ...!ut-sally!utastro!bigtex!james "Live Free or Die" Voice: (512)-323-2675 Modem: (512)-323-2773 5300B McCandless, Austin TX 78756
Re: chars in conditional expression, 3b2 C compiler
Author: Mike Stump
Date: Sat, 03 Jan 1987 23:44
Date: Sat, 03 Jan 1987 23:44
14 lines
1247 bytes
1247 bytes
In article <189@olamb.UUCP> kimcm@olamb.UUCP (Kim Chr. Madsen) writes: >In article <2489@sdsu.UUCP>, dlong@sdsu.UUCP (Dean Long) writes: >> Try these two commands on a 3b2 running SYSV unix on the following program: >> [edited for space] >Well, tried this one out without any problems on this 3b2 running UNIX >System V R2.1 are you running Release 3 or an older (pre 2.1 release) >system V. I tried it on 3b5 System V Version 2 release 2.0 and it bombs. Looks like they fix the problem in 2.1... Dean is probably running 2.0, like me. I will be happy when we upgrade to a 3b15, and S5V3... Mike Stump
Re: chars in conditional expression, 3b2 C compiler
Author: Doug Gwyn
Date: Mon, 05 Jan 1987 18:00
Date: Mon, 05 Jan 1987 18:00
11 lines
1144 bytes
1144 bytes
In article <189@olamb.UUCP> kimcm@olamb.UUCP (Kim Chr. Madsen) writes: -The only thing that really bugs me is the fact that chars are unsigned -and therefore the following code will fail: - while ((c=getc(stream)) != EOF) putchar(c); -And you will have to redefine EOF to 255 (0377 or 0xff) or cast it to a char! I suspect there will be a zillion follow-ups explaining that getc() returns an (int), not a (char), and that EOF should remain defined as -1. This has been hashed over many times in net.lang.c. It is not a bug in the 3B2 C implementation.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads