Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Browsing latest articles
Browse All 217 View Live
↧

Answer by Peter - Reinstate Monica for Why did the POSIX function...

We talk about an environment in which the system function to create a file is named creat, for heaven's sake; while it is the main error in the Unix design Ken Thompson would fix if he could do it all...

View Article


Answer by Peter - Reinstate Monica for Casting a void pointer in struct

Just for completeness, here is a live example. The key is to use the type tag enum to select the appropriate functions for each info type (like the following print functions) which would be virtual...

View Article


Answer by Peter - Reinstate Monica for Inline function linkage

It seems indeed counter-intuitive that an inline function has "external linkage" in C++ lingo; after all, the function symbol (its name) is not exported at all in the resulting object file — indeed,...

View Article

Answer by Peter - Reinstate Monica for Why having a function declared as...

The main effect of inline is to allow multiple definitions of the same function (because the definition is typically in a header included in multiple translation units).The name "inline" is a red...

View Article

Answer by Peter - Reinstate Monica for memset() to initialize object in...

The "memset approach" has two advantages over initializers for structures which are large but simple collections of data: It is clearer and has better maintainability.Clearer because it is obvious and...

View Article


Can we change the base address of an array through a pointer to array using...

Somebody wrote the following C program and asked why gcc allows "to change the base address of an array". He was aware that the code is terrible but still wanted to know. I found the question...

View Article

Answer by Peter - Reinstate Monica for C_programming: Static_function_Problem

Your problem statement is not very clear. The following program compiles for me:static void f() { } // <-- your B.cvoid f(); int main() { f(); }That is the compressed version of what you did (your...

View Article

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 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

Answer 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 Article

Cygwin/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 Article

Answer 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 Article


Answer by Peter - Reinstate Monica for What are the next steps to debug why...

You can delete your source code from the question, it is a distraction (or replace it with a "Hello World!"). Your problem is in the setup.You have two main ways to go about this: Use a fresh (possibly...

View Article

Comment by Peter - Reinstate Monica on How do I compile code that uses both...

@Caner-sagopaninsagkolu OK, that's a link error. The code sees the declarations, the compiler produces the proper calls, but the linker cannot resolve them. You need to add the libraries or .c files...

View Article


Answer by Peter - Reinstate Monica for git push --set-upstream to GitHub not...

As mentioned in the comments (thanks to matt, phd), this is possible with GitLab but not with github. The OP understandably but wrongly expected feature parity :).

View Article

Answer by Peter - Reinstate Monica for std :: gmtime does not return UTC time

This is a bit tricky. These functions are ancient. Both the gmtime()/localtime() pair as well as asctime()use static memory. Both re-use existing memory for subsequent calls, overwriting the result of...

View Article


Answer by Peter - Reinstate Monica for the open() function not being recognized

Even though it appears to be one of the most basic and ubiquitous C functions, open() is "implementation specific": It is a POSIX function. Now POSIX is an attempt to be "portable", but mostly between...

View Article

Answer by Peter - Reinstate Monica for What can a JIT compiler do that an AOT...

A JIT compiler can optimize based on run-time information which result in stricter border conditions which were not provable at compile time. Examples:It can see that a memory location is not aliased...

View Article

Comment by Peter - Reinstate Monica on Can I put arbitrary files (not...

@nega No, I want CMake to play my IDE nicely.

View Article

Answer by Peter - Reinstate Monica for Wrote a program to print prime...

I wanted to see whether it is possible to compute the primes at compile time with constexpr and give virtually instantaneous answers at run time.I found a solution for "compile time loops" with some...

View Article


Answer by Peter - Reinstate Monica for Why does "int *find(const vector&vec,...

Well, the idea is that not only is the vector constant but the standard library designers figured that the most reasonable semantics for a constant vector object is that its data is treated as constant...

View Article


Comment by Peter - Reinstate Monica on What's the difference between "C...

@interjay It is a (large) superset of the standard library, but the section 2 is explicitly system dependent.

View Article

Comment by Peter - Reinstate Monica on What happens if i mix c with c++ in a...

@HolyBlackCat You mean that the names then are global as well as in std? I didn't know that, actually!

View Article

Answer by Peter - Reinstate Monica for std::iota is very limited

With strides from C++23 you can writeiota(0) | stride(2)instead ofiota(0) | filter([](auto i) { return i % 2 == 0; })which feels much more clumsy and unnecessarily computing intensive (even if the...

View Article


std::async: does "as if in a new thread" guarantee that it is safe to use...

The 2020 standard says (23.9.9/4.1):If launch::async is set in policy, calls invoke(decay-copy(std::forward(f)), decaycopy(std::forward(args))...) (20.14.4, 32.4.3.3) as if in a new thread of execution...

View Article

Comment by Peter - Reinstate Monica on Why does x crash when I give it a...

@DrewDormann Well, it does not crash!

View Article

Answer by Peter - Reinstate Monica for Why does C++ introduce a "::" instead...

I hope this question will be closed soon (not because it is bad but because it has been asked and answered over at softwareenineering (where it doesn't belong either, by the way: It should be in...

View Article

Comment by Peter - Reinstate Monica on error: use of deleted function -...

@DominikKaszewski As I said elsewhere, the possibility of an invalid state is typically an advantage in my experience. If not, it is trivial to make that guarantee explicit.

View Article



Comment by Peter - Reinstate Monica on How change every struct in an array of...

@Barmar Good idea, didn't think of it.

View Article

Comment by Peter - Reinstate Monica on Is this declaration UB?

@IanAbbott re "My take is that modifying a member of a union will damage the values of the other members": It will change what the memory contains -- but I suppose that in the case of a const value,...

View Article

Comment by Peter - Reinstate Monica on Why do C and C++ support memberwise...

The compiler has complete information about an array (including its size, the number of elements and the size of each element) in exactly the same way it has complete information about a given struct....

View Article

Comment by Peter - Reinstate Monica on std::regex throws exception during...

The answer is B, right? ;-)

View Article


Comment by Peter - Reinstate Monica on Can a moved from object be moved again?

@3CxEZiVlQ One should perhaps add the caveat that this is less a question of language than one of quality of implementation. The language does not enforce in any way that the moved-from object is in...

View Article

Comment by Peter - Reinstate Monica on Could the vector begin() be deduced?

I'm not entirely sure about your statement about "the result of an expression is not affected by the context". For example, there is argument dependent lookup where function name lookup is expanded to...

View Article

Comment by Peter - Reinstate Monica on Could the vector begin() be deduced?

Well, operator<<'s meaning (to pick just the best known) strongly depends on the context it's used in! So that argument is not always applicable.

View Article


Comment by Peter - Reinstate Monica on In C++, can I use a preprocessor...

Upvoted for "No, and why would you?" ;-)

View Article


Comment by Peter - Reinstate Monica on How Does the Left-Hand Side (LHS) of...

@chqrlie Which, as an aside, indicates that the creators of C originally were a bit flip with their type system, for historical reasons (the predecessors it was built on, the state of the art when it...

View Article

Comment by Peter - Reinstate Monica on Should I go with if-else or match-case...

I don't know dataweave or mule, but in general: Often, there is a third choice: Use a dictionary/associative container that maps the inputs to outputs. That is a specific case of a general choice...

View Article

Comment by Peter - Reinstate Monica on Why does `free` in C not take the...

As an aside, the option to return (or pass, or assign, for that matter) a struct by value didn't exist in K&R ('The only operations allowed on a struct are member selection with "." and taking its...

View Article
Browsing latest articles
Browse All 217 View Live


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