Comment by Peter - Reinstate Monica on C strlen on char array
@JonathanLeffler What may not be obvious to C beginners is that string literals like "Hello" have an implicit extra character appended, the zero byte, even though it is not explicitly written. That is,...
View ArticleComment by Peter - Reinstate Monica on C strlen on char array
@hasaanE No, a segmentation fault is an irregular, abrupt end of the program wherever it just happens to be executing; the caller's code is never reached again. If strlen returns, there was a zero byte...
View ArticleComment by Peter - Reinstate Monica on Understanding "return *this"
It could be noted that references are often only syntactic sugar (or always, depending where your sugar ends). For example, if the functions returned pointers instead, one could write...
View ArticleComment by Peter - Reinstate Monica on C# For loop with try catch finally
There seems to be part of your suggestions missing where I inserted my commentary.
View ArticleComment by Peter - Reinstate Monica on Git Bash doesn't have any formatting
The missing colors and git magic in the prompt are due to some bash initialization files not being read. Maybe for some reason the .bashrc is in the wrong directory. There is sometimes a strange...
View ArticleComment by Peter - Reinstate Monica on Reading a newline
If you must reproduce the line breaks you must read line-wise, probably with fgets. (The usual problem of "max line length" exists (hopefully, your assignment specifies one).) You can then read the...
View ArticleComment by Peter - Reinstate Monica on How can I block for one request at a...
Shouldn't a (thread safe or manually locked) stack data structure work? Because its nature is "last in/first out" which is what you want. Requests go on the stack. When it's time to work on the next...
View ArticleComment by Peter - Reinstate Monica on how to know an enum class is sorted
Sounds as if you'd like a std::map with string/int (or int/string) pairs, not an enum. You can initialize it in the code much like you would an enum (even if it is not initialized at compile time).
View ArticleComment by Peter - Reinstate Monica on Complicated declarations in C
One reason pointers to arrays are not very useful is that such code (like the function here) can only handle arrays of that specific length. That's the underlying motivation for the adjustment of array...
View ArticleComment by Peter - Reinstate Monica on Understanding "return *this" and class...
It could be noted that references are often only syntactic sugar (or always, depending where your sugar ends). For example, if the functions returned pointers instead, one could write...
View ArticleAnswer by Peter - Reinstate Monica for What is the integer literal suffix 'i'...
I have been programming C for almost 40 years now and must admit: This question caught me off-guard.There is no integer suffix.In 6.4.4.1, "Integer Constants", of the C23 draft, the syntax of an...
View ArticleComment by Peter - Reinstate Monica on How do I configure portable parallel...
@Lap It is obviously a very good idea, indispensable. Almost all native build systems can build in parallel and there must be an interface for it.
View ArticleComment by Peter - Reinstate Monica on Why can't you initialize a single row...
You don't technically need to specify anything that is not not zeroed, I believe; or, cutting the negations, you don't need to specify anything that is zeroed; or, inverting the remaining negation: you...
View ArticleComment by Peter - Reinstate Monica on Remove auto generated exception code...
Wouldn't throw in a 32 bit program, would it? Perhaps use uint64_t...
View ArticleComment by Peter - Reinstate Monica on Is there any good reason to use C ()...
This is clearly not opinion-based -- there are a host of good objective reasons.
View ArticleCygwin/Msys2 mintty suddenly swallows or escapes AltGr keys (backslash, curly...
I'm using a German keyboard. On German keyboards, some characters have been turfed to an indirection with the right Alt key, labeled AltGr (I think English keyboards label that one simply Alt as well,...
View ArticleAnswer by Peter - Reinstate Monica for static library, but I still need headers?
Even though you can produce an executable from sources and library files with a single command, conceptually the process involves two steps (which you can perform separately if you wish):For each file...
View ArticleComment by Peter - Reinstate Monica on Code won't continue if i use 2 as the...
The presented code is much too long for me to study for any errors. (Massively) reducing the code in order to boil it down to the offending issue has two goals: (1) Other people can see the error...
View ArticleComment by Peter - Reinstate Monica on What does it do to juxtapose string...
It's more useful when a string is too long to fit into a single line, or if it is formatted or repetitive in a way that it makes sense to write corresponding parts below each other (example: ASCII...
View ArticleComment by Peter - Reinstate Monica on What does it do to juxtapose string...
Btw, I suppose you could use the compile-time sizeof (both part1 and part2 are true compile-time size arrays!) instead of the run-time strlen and avoid a variable length array.
View Article