delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/26/05:19:24

From: "DeHackEd" <dehacked72 AT nospam DOT hotmail DOT com>
Subject: Optmization and Exceptions
Date: Thu, 25 Dec 1997 19:27:48 -0500
Lines: 44
Message-ID: <OG5YUSZE9GA.170@upnetnews04>
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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).
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.

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)

#include <stdio.h>

main()
{
    printf("About to throw something\n");
    try
    {
        printf("In try...");
        throw "Strike 1";
    }
    catch (char *msg)
    {
        printf("Caught something: %s\n", msg);
        exit(1);
    }
    catch (int num)
    {
        printf("Error %d\n", num);
        exit(num);
    }
}

// This program does not link if -O3 compiled! Can you find the error?
// And you need to link in -lstdcx


- Raw text -


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