C (102/207)

From:Steffen
Date:13 Dec 99 at 20:09:59
Subject:Re: Optimizing (Was: Re: Getting desperate!)

From: Steffen <steffen.mars@stenloese.mail.telia.com>

On 13-Dec-99, Jonas Hulten wrote:

> From: Jonas Hulten <bjonte@hem2.passagen.se>
>
> Den 12-Dec-99, skrev Steffen:
>
>> From: Steffen <steffen.mars@stenloese.mail.telia.com>
>
>>> A guy once told me that C++ makes code bigger and slower. Anyone cares to
>>> comment on that?
>
>> Absolutely! The purpose of C++, i think, has never been speed, and for
>> some purposes, probably 'most', speed is irrelevant.
>
>> It seems that C++ causes a lot of structure copying, where you usually
>> would work the structures directly via pointers in C. Speed vs.
>> stability....
>
> I don't think C++ in itself causes more structure copying than C, it's just
> that you can use it or misuse it as you can use or misuse C. Structure
> copying can be avoided in C++ as it can in C in most cases.
>
> I don't think that the object oriented nature of C++ makes it slower, it
> just makes programs easier to write. You can do the same in C it just takes
> more code to do it. The first C++ compilers compiled to C first, so it is
> mostly some added nice syntax.

Example:

struct dummy{};

// The C way

Function(&dummy);

// The 'normal' or should i say 'recommended' C++ way

Function(dummy);

/*
Wich will cause Function() to receive a copy of dummy, not the actual structure. AFAIK. Ofcourse you may use the 'C' method in C++, but it's safer to work with a copy of the object instead of the object itself. I think it's a 'datahiding' thing so that you can make structures 'read-only' where aplicable.
*/