Comment by Peter - Reinstate Monica on Can a local variable's memory be...
@AviShukron Re "freedom C++ gives the developer": Most languages, including C# and Ada, allow unchecked access to memory addresses which gives you the same freedom. Perhaps the difference is that this...
View ArticleComment by Peter - Reinstate Monica on the open() function not being recognized
Seems in io.h for me, and you need to say #pragma warning(disable : 4996). ("The name is deprecated because it doesn't follow the Standard C rules for implementation-specific names.")
View ArticleAnswer 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 ArticleAnswer 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 ArticleComment by Peter - Reinstate Monica on How can I view Markdown text inside...
I never understood the ban of questions for recommendations. This is extremely helpful -- as the many upvotes attest, helpful for many other as well! -- and I have much more faith in the crowd-based...
View ArticleAnswer by Peter - Reinstate Monica for Non const lvalue references cannot be...
A temporary lives, as the name suggests, only briefly. It is normally destroyed at the end of the expression of which it is a part, that is, at the next semicolon or, rarer, at the end of the...
View ArticleComment by Peter - Reinstate Monica on How do I fix this 5-bit boundary based...
The issue is likely that for the first bit field, the compiler "allocates" an object of the specified member type, which in your not-working example was an 8 bit int. It then fits successive bit field...
View ArticleComment by Peter - Reinstate Monica on How do I fix this 5-bit boundary based...
While they are non-portable, they are designed exactly for the OP's purpose: Fit data into an externally imposed format. To this end, it is specified that the bit fields are adjacent; IIUC, the main...
View ArticleComment by Peter - Reinstate Monica on How do I fix this 5-bit boundary based...
I edited the question, incorporating the expected layout information from your answer in the question. Roll back (or edit at will) if you are unhappy.
View ArticleComment by Peter - Reinstate Monica on How can I clean up c++ terminated...
"A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable." When you want to exit the main thread you join the...
View ArticleComment by Peter - Reinstate Monica on When a struct member is a struct, its...
Your code does not really show the premise, does it? The only struct used as a member here, W, has only bytes as members, hence no alignment requirements or even desires. I bet you the compiler makes...
View ArticleComment by Peter - Reinstate Monica on When a struct member is a struct, its...
Dynamic allocation is another reason, besides arrays, for middle-padding (on the stack, the compiler could simply allocate S1s at odd addresses, but malloc() must return aligned memory).
View ArticleComment by Peter - Reinstate Monica on When a struct member is a struct, its...
@dsyx Well, you can limit compiler dependencies by using explicitly-sized types (which you are already doing). You can control the remaining dependencies by using compiler specific methods (pragma...
View ArticleComment by Peter - Reinstate Monica on Fastest way to check if string...
What's the maximum length for, say, 90% of the strings?
View ArticleComment by Peter - Reinstate Monica on Casting a tuple to tuple is causing an...
@user12002570 Which is exactly what's happening here, isn't it? The temporary created by make_tuple is destroyed as soon as the construction of data is finished, leaving the const ref dangling.
View ArticleComment by Peter - Reinstate Monica on Why am I getting an int as an answer...
As an aside, the sequence of events you report contains the explanation: You already know the (undesired truncated integer) result of val1/val2 because you started by printing that directly. Assigning...
View ArticleComment by Peter - Reinstate Monica on Can you find a real example of "time...
"without using a virtual machine, running your code on bare metal"? Is there a third option? Also, godbolt does not count? Also, increasingly, even on single-user, consumer workstations code is more...
View ArticleComment by Peter - Reinstate Monica on Console Application crashing when...
Your program is crashing, and you can use a debugger to find out where. If the system allows and is configured that way, the program may leave a core dump that can be inspected with the debugger. Just...
View ArticleComment by Peter - Reinstate Monica on How to determine the printf format...
Nice idea; one disadvantage will be a speed penalty though.
View ArticleComment by Peter - Reinstate Monica on How to determine the printf format...
I'm not sure what I'm missing. Wouldn't a handful of manually overloaded constexpr functions do, possibly with a template catch-all that throws?
View Article