The tag has no wiki summary.

learn more… | top users | synonyms

6
votes
3answers
138 views

Passing parameters that need to be copied by value or const reference

I have a basic (mathematical) vector class, which in my opinion benefits from C++'s operator overloading. Vector-scalar operations are defined as self-modifying functions in the class itself, class ...
6
votes
4answers
532 views

Does internal state “leak” when it influences externally-visible behavior?

I have a method (in C++) which generates a value based on a parameter and the parameters from previous calls. Calling it more than once with the same parameter may generate different values each time. ...
0
votes
1answer
75 views

Is it a bad idea to use mutable for pre-allocated temporaries?

Let us assume I have the following C++ class: class MyFastMessageEncoder { public: MyFastMessageEncoder() : m_fieldEncoder(ENCODING_STYLE_DEFAULT) { } void ...
0
votes
2answers
66 views

Mutable cursor in readonly object?

I've been searching for the different uses of the keyword mutable. I've found that it is generally used for caching, lazy computing, mutex, ... But I'm wondering if it is coherent to use it for a ...
11
votes
4answers
757 views

What are the problems of bringing C++-like const into a language?

I am interested in the idea of C++-like const not that particular execution (like casting away const). Take for example C# -- it lacks C++-like const, and the reason for it is the the usual -- people ...
2
votes
1answer
281 views

Are there advantages to declaring stack variables constant in C++

It's not clear to me what benefits there are of declaring your stack variables as constant in C++, I was hoping somebody might explain the benefits and purpose for this technique. For example: void ...
2
votes
1answer
365 views

Which is better to use? (Enum or Constant)

I have my enum like this. enum Size{PAGE_SIZE=20, HEADER_SIZE=30 }; I only use them as constants(No enum variable created) in my program. i.e= int x = PAGE_SIZE + 20; So what is the ...
12
votes
4answers
949 views

When and for what purposes should the const keyword be used in C for variables?

While getting my code reviewed here the issue of using the const keyword came up. I understand that it is used for implementing read-only behaviour on variables. I am confused about what are the ...
1
vote
1answer
127 views

Implementation defined behaviour changing const type in c

The C standard states that if an attempt is made to change a const type,the result is implementation defined.This gives error on my system,but what does it depend on(compiler,os)? What are the ...
2
votes
2answers
387 views

In C# what is lifetime or lifespan of constant variable?

In C# if i declare a constant variable is any memory allocated to it as it acts as a compile time replacement? How long is the variable's life?
3
votes
4answers
1k views

Immutable Method in Java

In Java, there is the final keyword in lieu of the const keyword in C and C++. In the latter languages there are mutable and immutable methods such as stated in the answer by Johannes Schaub - litb ...
2
votes
1answer
62 views

Reading data from file and const

Is it sane to let a read method on a file object to be const? For example size_t read(void* buffer,size_t length) const; The read method does not change the contents of the file, but updates the ...
9
votes
5answers
796 views

Zero as a constant?

I have come across this programming idiom recently: const float Zero = 0.0; which is then used in comparisons: if (x > Zero) {..} Can anyone explain if this is really any more efficient or ...
6
votes
2answers
3k views

Do people use const a lot when programming in Objective C?

Related: “sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers” warning Sometimes, I think it's useful though. I may need to pass an a table and want to make sure that the ...
8
votes
5answers
4k views

Difference between immutable and const

I've often seen the terms immutable and const used interchangeably. However, from my (little) experience, the two differ a lot in the 'contract' they make in code: Immutable makes the contract that ...