Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Browsing all 70 articles
Browse latest View live

Comment by Peter - Reinstate Monica on Ambiguous constructor error in gcc but...

Even really simple things are really hard to understand in modern C++. Not even the compiler builders understand the language any longer. Does not bode well for usability.

View Article



Comment by Peter - Reinstate Monica on Is *pt +++= 20 valid?

@jayatubi I am not sure. gcc does not complain (but does complain when I add a certainly undefined statement, like *pt++ = *pt++;).

View Article

Comment by Peter - Reinstate Monica on Is *pt +++= 20 valid?

Just to point out that the bad practice of *p++ was introduced in K&R's TCPL, which had the role of a language specification in the first decade or two. I'm actually not sure whether I disagree...

View Article

Comment by Peter - Reinstate Monica on Redeclaring variables in C

You write/declare it once in the static C code; but at runtime, its declaration is passed and its initialization is performed many times. All modern mainstream compilers would pull that constant...

View Article

Comment by Peter - Reinstate Monica on Use of goto to continue from several...

Interestingly, because while(1) is essentially nothing but a jump destination itself, the main_loop label could as well be inside the loop, after the while!

View Article


Comment by Peter - Reinstate Monica on How can I validate that an user enter...

Note that this is the expected behavior though. It makes a lot of sense to skip all whitespace -- for example, imagine your program reads actually from a file; then this leniency imposes fewer...

View Article

Comment by Peter - Reinstate Monica on Why is my integer math with std::pow...

To the common user, gcc comes bundled with libraries as a unit.

View Article

Comment by Peter - Reinstate Monica on Different IDEs are giving different...

@john How can you say it is not wrong? This wrong result may be allowed by the standard, but that doesn't make it right.

View Article


Comment by Peter - Reinstate Monica on Bash command groups: Why do curly...

One consequence of making characters like { reserved words and not metacharacters is that they can appear unquoted in many contexts, for example as file names including command names (after all, the...

View Article


Comment by Peter - Reinstate Monica on How to Implement a Create() Function...

@paddy In your example, I think it would be more illuminating to not use auto for the shared pointers; also, I would let Create() make return a shared_ptr of the actually created type, i.e. static...

View Article

Comment by Peter - Reinstate Monica on Is it safe to use a current object...

@GarrGodfrey Why would the union change its contents if the containing object's destructor is executed? As pointed out here, the union's destructor is actually deleted, so it is not called. Of course,...

View Article

Comment by Peter - Reinstate Monica on C++ const_cast surprising outcome

The reason this is undefined behavior is that a truly const object may well end up in read-only memory on some (for example, embedded) systems! This is not the case on a "normal computer" though; the...

View Article

Answer by Peter - Reinstate Monica for Correct way to 'glue' two class...

I assume you are unhappy about the code duplication (stupid repetitions!). Some duplication is unavoidable with delegation (here: Let an existing implementation —ClassBImp— do another interface's...

View Article


Answer by Peter - Reinstate Monica for How do I spoof the current date when...

I think, as I said in comments, that Cole's suggestion to shadow /bin/date with a function like date(){ echo 'something else'; } is the best solution.Another approach would be to separate concerns: Let...

View Article

Answer by Peter - Reinstate Monica for Token concatenation using ## for Array...

The issue is with the way tokenization works. The gcc documentation has a page about tokenization and concatenation from which I glean the following:The preprocessor separates the source code into...

View Article


Answer by Peter - Reinstate Monica for Is it possible to make each index in...

Remember that elements in an array (and, because a vector uses an array internally, in a vector) are each proper objects. Defining single variables like a, b, c etc. and putting pointers to them in a...

View Article

Answer by Peter - Reinstate Monica for Inheritance in C++ for a class project

One traditional reason inheritance was invented was to re-use code in base classes. Client has an input operator; the input operator for the derived class Campaign should first call the input operator...

View Article


Answer by Peter - Reinstate Monica for I need help resetting an integer, or...

Your problem is that you create a new object of the class Random every time you enter the function. First of all, this is wasteful: The garbage collector at some point must destroy all the lost...

View Article

Answer by Peter - Reinstate Monica for Why is 'char -> int' promotion, but...

The promotions are a subset of conversions performed implicitly in certain circumstances, even if the target type is not given. Here are two of them:Many built-in arithmetic operators "promote" their...

View Article

Answer by Peter - Reinstate Monica for C program return 1 if x > 0, 0 if x =...

I'm not sure whether that would be considered cheating but you can simply exploit the implicit evaluation of integers as booleans in C's control structures. That is, you can simply branch depending on...

View Article
Browsing all 70 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>