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

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

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

Answer by Peter - Reinstate Monica for How define an array of function...

There are a number of correct answers here; but they fail to mention the beautiful simplicity of the C grammar which, once understood, helps solving question like this one.1. Declarations syntactically...

View Article



Comment by Peter - Reinstate Monica on Why is it ok to cast to an undeclared...

Is there a standard quote for a cast being an "implicit declaration"?

View Article

Comment by Peter - Reinstate Monica on Why is it ok to cast to an undeclared...

Valid points except "Casting from a raw address into a pointer to incomplete struct type is probably senseless": It makes as much sense as any other pointer cast to an incomplete type, which is not...

View Article

Comment by Peter - Reinstate Monica on Why does the arrow (->) operator in C...

Alogol68 automatically dereferences pointers ("refs") when necessary from the context. Strictly spoken, that was probably the case for something like i+1, i being an integer variable: Because a...

View Article

Comment by Peter - Reinstate Monica on Ensuring an array of ints is actually...

What keeps you from writing a class (possibly a std::array or std::vector wrapper) that has the terminating 0 as an invariant and provides an operator int*()?

View Article


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

Comment by Peter - Reinstate Monica on c++ warning: enumeration value not...

@JesperJuhl I agree with you but partly because I'm working in a safety critical domain. For "casual" SW development I understand it can be a nuisance. And I can reboot my remote once a week, np; but...

View Article

Comment by Peter - Reinstate Monica on c++ warning: enumeration value not...

I disagree with the "no if-chain" advice. If you want to handle 2 out of hundreds of possibilities a switch seems the wrong choice, semantically but also, relatedly, for readability. if - else if -...

View Article


Comment by Peter - Reinstate Monica on Why is subtracting these two...

@PabloH Wow, that is a good point. There are "physical dates" (sunrise) and "logical dates" (trains, dentists). Had never occurred to me.

View Article


Comment by Peter - Reinstate Monica on Are these all the types of variadic...

I think this is actually a great question. Any attempt to compile encyclopedic knowledge is laudable, be it about (in this case widely used) proprietary APIs or standards. I think I have never seen...

View Article

Comment by Peter - Reinstate Monica on Sed is changing the endlines from CRLF...

That is annoying. sed should leave all bytes alone that are not undergoing substitution.

View Article
Browsing latest articles
Browse All 239 View Live


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