www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/07/06/23:09:40

From: Mat Hostetter <iclone!mjhostet AT cs DOT unm DOT edu>
Date: Tue, 6 Jul 93 20:34:25 -0600
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: How do you eliminate dead code?

gcc -O does eliminate dead code, and has done so for a very long  
time.  I compiled this with gcc -O2 -m486 -S, with gcc ~2.3.3,  
although I haven't tried it with the latest gcc distributed with  
djgpp.

#include <stdio.h>

int
main (int argc, char *argv[])
{
  if (0)
    fprintf (stderr, "This shouldn't exist.\n");
  return 0;
}


and got this assembly:


	.file	"foo.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
LC0:
	.ascii "This shouldn't exist.\12\0"
	.align 4
.globl _main
_main:
	pushl %ebp
	movl %esp,%ebp
	call ___main
	xorl %eax,%eax
	movl %ebp,%esp
	popl %ebp
	ret


What version of gcc are you using?

-Mat

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019