Re: where do declare a variable?
- From: "Bo Persson" <bop@xxxxxx>
- Date: Thu, 22 Nov 2007 20:32:43 +0100
Joseph M. Newcomer wrote:
:: See below...
:: On Thu, 22 Nov 2007 13:06:54 +0100, "Bo Persson" <bop@xxxxxx>
:: wrote:
::
::: Vaclav wrote:
::::: In fact, I started to think about this when LINT suggested (for
::::: sample 1) that QLin* pLin should be declared as const. Can that
::::: make a difference (adding const) in the code generated by the
::::: compiler?
:::
::: It doesn't affect the code in any way.
:: ***
:: Actually, this is not true. const can have a profound effect on
:: code quality given the right circumstances. (a) why do you think
:: it has no effect? (b) under what conditions did you determine this?
::
:: As someone who regularly took advantage of const declarations in
:: writing compiler code, I can say that it is a good practice for
:: something that is not modified. ****
Sure, it is a good practise. I use it all the time. :-)
However, the compiler knows if a variable is modified or not. That's
how it can tell me if I try to assign a new value to something
declared const.
:::
::: It does affect the compiler's ability to tell you when you are
::: accidentally changing the value. If it is supposed to stay the
::: same all the time, adding a const shows that intention.
:: ****
:: It affects common subexpression computations, code flow (both
:: alpha and omega flows), and value propagation.
:: ****
But it doesn't matter if I tell the compiler or not. I has to check
this for itself anyway.
Bo Persson
.
- Follow-Ups:
- Re: where do declare a variable?
- From: Joseph M . Newcomer
- Re: where do declare a variable?
- References:
- where do declare a variable?
- From: Vaclav
- Re: where do declare a variable?
- From: Joseph M . Newcomer
- Re: where do declare a variable?
- From: Vaclav
- Re: where do declare a variable?
- From: Bo Persson
- Re: where do declare a variable?
- From: Joseph M . Newcomer
- where do declare a variable?
- Prev by Date: Re: How to verify if a class is registered
- Next by Date: Re: static and globals in a thread environment
- Previous by thread: Re: where do declare a variable?
- Next by thread: Re: where do declare a variable?
- Index(es):
Relevant Pages
|