Quantcast
Browsing all 223 articles
Browse latest View live

Answer by Peter - Reinstate Monica for Pointer expressions: *ptr++, *++ptr...

Here is a class which documents all the relevant functions on stderr. I try the three expressions you mention in a program:#include <iostream>#include <string>using namespace std;struct...

View Article


Answer by Peter - Reinstate Monica for How do programs in unix know whether...

Shells open a pipe between the two processes linked by a pipe symbol|. The shells (sh, ksz, zsh, bash) differ a bit in how exactly they implement that (for example: is one process the executing shell...

View Article


Comment by Peter - Reinstate Monica on Why Does a Program Compile and Run...

Ah, snake oil (snake oil because the antivirus program in fact exposes the largest attack surface on your computer, since it must open and inspect all file types) ... anyway: I would expect that any...

View Article

Comment by Peter - Reinstate Monica on Are char8_t and char16_t dynamic in size?

@Crackie The underlying data storage to use for utf-8 would be a (possibly unsigned) char array, preferably that within a vector, or even more preferably, within a custom class.

View Article

Comment by Peter - Reinstate Monica on String to unsigned char in C or C++

I don't understand the question. I suppose you want to "convert" (i.e., read) the file into an array of chars. Why do you have an initialized array here? If it's the target array, it doesn't need...

View Article


Comment by Peter - Reinstate Monica on C++ function with const pointer parameter

Re "In the second case you are trying to create a non-const pointer from a const one": No. the OP is trying to create a pointer to non-const from a pointer to const. None of the pointers themselves is...

View Article

Comment by Peter - Reinstate Monica on C++ function with const pointer parameter

Generally spoken, declarations mimic usage -- const Node *p declares something that can be changed (it is not const) and, when dereferenced (*p), yields a type const Node. By contrast, Node * const p...

View Article

Comment by Peter - Reinstate Monica on Fisher-Yates shuffle: Who is right,...

As an aside, the branch is probably costlier than simply performing the swap for integers; it's likely there for more elaborate (value) types.

View Article


Comment by Peter - Reinstate Monica on int (*number)[2] returns a 2D array or...

@Lundin I'm not familiar with the site but it does parse the example correctly.

View Article


Comment by Peter - Reinstate Monica on What is the purpose of (int *) p here?

@Ry- Mistake or intention -- in any case it is (like most code involving pointers to arrays) rather unidiomatic and unnecessarily complicated. int *pint = s[i]; would be more common: s[i] is an array...

View Article

Comment by Peter - Reinstate Monica on How to open a file with append mode...

This "stepped" approach works in "casual" situations but contains a "race condition": If another program tries to open or create the file in parallel, it may create it between the point when you check...

View Article

Comment by Peter - Reinstate Monica on How to refer to the filepath of test...

@WeatherVane is correct, usually; furthermore, tests are often started by scripts or in a test environment of some sort (Jenkins etc.) which has its own ways of referring to files and directories.

View Article

Comment by Peter - Reinstate Monica on Why does the following C code enter an...

@EricPostpischil Ah, interesting! Thanks. I deleted my comment. I suggest you leave yours in place; it is an interesting piece of information.

View Article


Comment by Peter - Reinstate Monica on Cannot open include file: 'stdio.h' -...

I'm pretty sue that this can be set as a default for new projects.

View Article

Comment by Peter - Reinstate Monica on In pygame for event.type ==...

I suppose you mean " thin SDL wrapper (not SQL)?

View Article


Comment by Peter - Reinstate Monica on How do I create an abstract class...

Yes, they need to receive the base argument type, and, what's important, probably you want it by reference. Passing the argument by value instead will compile but "slice" the derived argument type into...

View Article

Use of dependent type name in recurring template [duplicate]

I am surprised that the following code does not compile. Am I doing something wrong or is this simply not possible? Why does the compiler recognize the function name DerivedT::Df but not the type name...

View Article


Comment by Peter - Reinstate Monica on Where to download C++ WinApi libraries...

@Osyotr Wouldn't the presence of the header indicate that the library is installed somewhere?

View Article

Comment by Peter - Reinstate Monica on What does statically casting...

The main thing it does is that it changes the type of the expression to std::underlying_type<T> ;-). if you ask "what does it do that the C style cast doesn't do" then the answer is "nothing"....

View Article

Comment by Peter - Reinstate Monica on Can I use dd to repeat printf output?

Well, if you say printf '\x00\x00\x00\x01\x00\x00\x00\x01' | dd bs=4 count=1024 of=test.bin, I would expect 8 bytes. What about for i in {1..1024}; do printf '\x00\x00\x00\x01'; done | dd bs=4...

View Article
Browsing all 223 articles
Browse latest View live


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