delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/26/14:53:22

Date: Fri, 26 Dec 1997 11:53:06 -0800 (PST)
Message-Id: <199712261953.LAA12208@adit.ap.net>
Mime-Version: 1.0
To: "DeHackEd" <dehacked72 AT nospam DOT hotmail DOT com>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Optmization and Exceptions

At 07:27  12/25/1997 -0500, DeHackEd wrote:
>I was just playing around with the C++ compiler and I noticed a few things:
>
>1) Without optmizations, strlen("string literal") evaluates to asm
>LC1:
>    .ascii "string literal\0"
>
>pushl $LC1
>call _strlen
>
>But with -O3, it just evaluates to $14 (I think - I can't count).
True. `strlen' is among the functions which GCC automatically compiles
inline. Here it performs a further optimization and finds the result at
compile time. If you use `-fno-builtin', you will get a call to the library
function instead.
>2) With or without optmizations, (12*5) evaluates to $60, not a long asm output
>for calculating it. This is something which came up as a problem on some
>newsgroup.
Why would this be a problem? IMHO, most people expect compilers to do smart
things. Most compilers I have seen will calculate obvious constant
expressions at compile time. I can't think of any reason for a superfluous
multiplication to be performed, unless a delay is wanted. In that case, the
programmer should code it in inline assembly, since it will be
machine-specific anyway.
>
>3) Exceptions often cause the compiler to have an internal compiler error
>message. Take a look at a simple program like this (I know I am using C, not
>C++, screen routines, but it makes the output much nicer)
[snipped]
Exceptions are still under development in G++. You must compile with
`-fhandle-exceptions' to make them work at all, and apparently you can only
use a few or the compiler aborts.

HTH

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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