Re: List<> of struct with property. Cannot change value of property. why?

Tech-Archive recommends: Fix windows errors by optimizing your registry



After all, in C++ there's a LOT of code that doesn't modify data that
isn't marked "const". Relying on the "const" keyword to enable a warning
wouldn't have been a good idea in C++, because you'd get a lot of false
positives due to the large amount of code that is "const" without using
"const".

Actually, in a good programmer's hands, that's a notice to the compiler that
the function is not guaranteed to leave the data unchanged. I'd hate for
the compiler to analyze a stub function, make an automatic determination of
const-ness, and somehow affect how the code around it is error-checked.
(Note that optimizing the generated machine code is ok, optimizing away
errors and warnings is not).

Understanding and using const-correctness is a prerequisite for being a
professional C++ programmer. It's an important part of documentation,
compile-time error checking, and enables automatic optimizations that
couldn't otherwise be performed.


.



Relevant Pages

  • Re: "Sorting" assignment
    ... too slow, other times for optimizing too much, some times for being too ... That is a rather bizarre, not-quite-C compiler, but ok. ... The overlap issue is a different problem, but performing a "swap" on ... CPU hardware feature differences that can be incredibly important to ...
    (comp.programming)
  • Re: Why INFINITE loop in a thread occupy so much CPU time??
    ... measuring code quality or program efficiency. ... You stated the K&R compiler did the silly thing of testing ... In debug mode, nothing, repeat nothing, matters. ... my Ph.D. is in optimizing compiler technology. ...
    (microsoft.public.vc.mfc)
  • Re: Compiler code optimization: see code below
    ... >>I'm writing some C to be used in an embedded environment and the code ... I'm using GCC for the workstation and Diab compiler for the ... >>sure what exactly a good optimizing compiler can optimize away. ... > Neither optimization nor efficiency is defined by the C standard. ...
    (comp.lang.c)
  • Re: How about this syntactic candy?
    ... Unless the code in the loop is so simple that it is guaranteed that the list.Count property won't change during the execution of the loop, optimizing the expression to avoid reevaluating list.Count would be wrong. ... I once saw a demo of a for loop all compressed into one line with ingenious shortcuts and contractions, and after the optimising compiler had been through it, it generated EXACTLY the same machine code as an alternative loop written out in full. ... In that case, I could see the utility in providing the compiler with an explicit statement to that effect, but it seems to me that the current method required is so easy and simple, I can't imagine the point in adding something extra to the language to support the behavior. ...
    (microsoft.public.dotnet.languages.csharp)
  • amd64 bitops fix for -Os
    ... filesystem, the kernel mostly hangs. ... When optimizing for speed, the generated code is such that the flags ... Obviously the asm statement must not rely on the compiler setting up ... -inline long find_first_zero_bit(const unsigned long * addr, ...
    (Linux-Kernel)