[comp.sys.mips] cc bug?

grunwald@foobar.colorado.edu (Dirk Grunwald) (07/13/90)

> RISC/os 4.01
> cc 2.0
> 
> # include	<stdio.h>
> 
> main ()
> {
> char	*str;
> 
> 	fprintf (stderr, "why does this compile?\n"< str);
> }
---

	this is roughly:

	char *foo = "why does this compile?\n";
	char *str;
	int condition = foo < str;
	fprintf(stderr, condition);


and the value of condition would be either 0 or 1. Probably 0. When
fprintf attempt to print the null and/or garbage string living at
address 0 or 1, it barfs.

rogerk@mips.COM (Roger B.A. Klorese) (07/13/90)

In article <2742@uakari.primate.wisc.edu> bin@primate.wisc.edu (Brain in Neutral) writes:
>RISC/os 4.01
>cc 2.0
>
># include	<stdio.h>
>
>main ()
>{
>char	*str;
>
>	fprintf (stderr, "why does this compile?\n"< str);
>}
>
>Note the < rather than , after the \n ... it compiles but dumps core when
>run.  Why does it even compile?

It compiles because

	"why does this compile?\n" < str

is a boolean-valued expression, and your fprintf is now missing a third
argument, which is why it dumps core.
-- 
ROGER B.A. KLORESE      MIPS Computer Systems, Inc.      phone: +1 408 720-2939
MS 4-02    950 DeGuigne Dr.   Sunnyvale, CA  94086   voicemail: +1 408 524-7421
rogerk@mips.COM         {ames,decwrl,pyramid}!mips!rogerk         "I'm the NLA"
"Maybe this world is another planet's hell." -- Aldous Huxley

bin@primate.wisc.edu (Brain in Neutral) (07/13/90)

>> 	fprintf (stderr, "why does this compile?\n"< str);

etc.  Well, as has been pointed out to me, this is just a boolean expression.
I *thought* I must have just been looking at it wrong...

argh.

Paul DuBois
dubois@primate.wisc.edu