C (114/207)

From:Steffen
Date:15 Dec 99 at 08:34:02
Subject:Re: Optimizing (Was: Re: Getting desperate!)

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

On 14-Dec-99, Pieter Ennes wrote:

> From: Pieter Ennes <ennesp@wins.uva.nl>
>
> Hi amiga-c,
>
> On Mon, 13 Dec 1999, Steffen wrote:
>
>> From: Steffen <steffen.mars@stenloese.mail.telia.com>
>>
>> On 13-Dec-99, Jonas Hulten wrote:
>>
>>>>> 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);
>
> You think? In C++ you can also declare your function as:

Try reading the words 'normal' and 'recommended' again.

> void Function(dummy &dum); // Prototype

Yes, i know. That's why i didn't write it was the *only* way to do it. If you're absolutely sure you know what you're doing, you can use that aproach, but it is still safer to work with structures that are read-only, wich is what i see is one of the points of C++, to make the programs more stable (and easier to write, especially with big progs).

> In this case a 'reference' to dummy gets passed and you get something that
> looks like a normal structure (with all advantages), but technically is a
> pointer. You address it with a '.', not '->'.

Have i claimed otherwise ?

>> /*
>> 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.
>> */
>
> Using such a reference, you are able to 'const' anything you like...

What has constants got to do with it ?