Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Filter by
Sorted by
Tagged with
3 votes
2 answers
115 views

shortcircuiting logical expressions in preprocessor - actually specified in the C standard?

I'm looking at the C17 standard. Chapter 6.10, Preprocessing directives if-group:# if constant-expression new-line groupopt Chapter 6.5 Expressions-> Chapter 6.6 Constant expressions 11 The ...
Sterpu Mihai's user avatar
0 votes
1 answer
130 views

Is there a way in Laravel to bulk-insert multiple records and get Eloquent models (all inserted fields) returned? [duplicate]

I have a scenario where I need to insert multiple records at once. I want to achieve all two: Bulk insert multiple records at once (performance). Return Eloquent model instances for the inserted ...
Ləman Əmrahova's user avatar
1 vote
1 answer
164 views

Is it standard compliant to declare DTSTART without time zone?

I booked a train ticket with Trenitalia, the Italian train company. They sent an email with attached ICS files with the travel information. When I import that ICS in Thunderbird, the time of the train ...
robertspierre's user avatar
0 votes
2 answers
98 views

How to semantically indicate that a webpage is available in multiple languages

Is there a standard way that an HTML page written in one (human) language can indicate that a translation is available in another language? I know that I can mark up some text manually, saying ...
mattp's user avatar
  • 82
3 votes
1 answer
98 views

Why is it not possible to extend a function call expression returning multiple values with another value on the right in Lua

Consider this test case. function test() return 1, 2, 3 end -- OK: prints 4 1 2 3 print (4, test()) -- NOT OK: prints 1 4 print (test(), 4) Why do values returned from a function in a function ...
GreenScape's user avatar
  • 7,927
5 votes
1 answer
186 views

Why are [[no_unique_address]] members not transparently replaceable?

In the classic talk An (In-)Complete Guide to C++ Object Lifetimes by Jonathan Müller, there is a useful guideline as follows: Q: When do I need to use std::launder? A: When you want to re-use the ...
xmllmx's user avatar
  • 44.5k
4 votes
2 answers
183 views

Why is `iterator_category` deleted in `std::views::concat::iterator` if it's a pure input iterator?

In the C++26-adopted proposal p2542, i.e. std::views::concat, there is a confusing statement: The member typedef-name iterator_category is defined if and only if all-forward<Const, Views...> is ...
xmllmx's user avatar
  • 44.5k
-1 votes
1 answer
164 views

Why is `std::views::as_rvalue` not so cheap as `std::move_iterator`? [closed]

Consider the following code snippet (full code: https://godbolt.org/z/PMM4z9KvM): int main() { { std::cout << "begin std::views::as_rvalue\n"; auto iss = std::...
xmllmx's user avatar
  • 44.5k
2 votes
2 answers
123 views

Why can I not efficiently move the strings when using std::istream_iterator<std::string>?

#include <fstream> #include <string> #include <vector> int main() { auto fin = std::ifstream("tmp.txt"); auto pos = std::istream_iterator<std::string>(fin);...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
144 views

Are `asctime_r` and `ctime_r` standard in C?

As we already know, asctime and ctime are not thread-safe since they return a pointer of the internal static variables, cppreference only list the alternatives asctime_s and ctime_s which receive ...
Sprite's user avatar
  • 4,149
0 votes
1 answer
182 views

Why is a lambda expression not just the syntactic sugar of a functor?

Consider the following code: int main() { int n = 0; return [n] { return n; }(); // ok } According to https://cppinsights.io, the code above will be translated into the following code: int ...
xmllmx's user avatar
  • 44.5k
2 votes
1 answer
131 views

Must T be unqualified in std::allocator<T>?

gcc, clang, and msvc all reject the following code: #include <memory> #include <vector> int main() { auto _ = std::vector<int const>{}; // error auto _ = std::vector<...
xmllmx's user avatar
  • 44.5k
1 vote
2 answers
160 views

Why does static_cast not work as the cppref site says in such a case?

Consider the following code: struct A { int n; double d; }; int main() { auto a = A{.n = 1, .d = 3.14}; // error: static_cast from 'int*' to 'A*' is not allowed auto _ = ...
xmllmx's user avatar
  • 44.5k
0 votes
1 answer
193 views

Do we really need std::start_lifetime_as if a well-defined alternative already exists?

Consider the code example excerpted from cppref: #include <complex> #include <iostream> #include <memory> int main() { alignas(std::complex<float>) unsigned char buf[...
xmllmx's user avatar
  • 44.5k
0 votes
0 answers
115 views

Does a local constexpr variable occupy the stack space? [duplicate]

constexpr int f(int idx) { constexpr auto arr = std::array<int, 1'000'000'000>{}; // stack overflow? return arr[idx]; } int main() { return f(1024); } Does arr occupy the stack ...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
223 views

Why is `""s.size()` legal, but `5ms.count()` is not? [duplicate]

#include <chrono> #include <string> using namespace std::literals; int main() { ""s.size(); // ok (""s).size(); // ok (5ms).count(); // ok 5ms....
xmllmx's user avatar
  • 44.5k
0 votes
2 answers
134 views

Why can a const object call a non-const member function? [duplicate]

Consider the following code: int main() { auto const fn = [] mutable {}; fn(); // ok, why? } As per the latest C++ standard draft [expr.prim.lambda.closure] 7.5.6.2/6 (emphasis mine): The ...
xmllmx's user avatar
  • 44.5k
8 votes
1 answer
459 views

Why is decltype(ConstInt{}) not const?

Consider the following code: #include <concepts> #include <string> using ConstInt = int const; using ConstStr = std::string const; static_assert(std::same_as<std::string const, ...
xmllmx's user avatar
  • 44.5k
4 votes
1 answer
242 views

Why were charN_t designed as built-in types, but std::byte was not?

Why were char8_t, char16_t, char32_t designed as built-in types, but std::byte was not? As per the C++ philosophy, if something can be implemented in the library, we almost always prefer doing so to ...
xmllmx's user avatar
  • 44.5k
3 votes
3 answers
248 views

Does trivially copyable imply trivially relocatable?

C++26 will introduce std::is_trivially_relocatable_v, and the proposal author states: Trivially copyable implies trivially relocatable. However, I think the statement might not always be true, ...
xmllmx's user avatar
  • 44.5k
2 votes
1 answer
117 views

Why do we keep a redundant ctor in std::copyable_function?

According to the C++ docs, std::copyable_function has two overloaded ctors as follows: template<class T, class... CArgs> explicit copyable_function(std::in_place_type_t<T>, CArgs&&...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
186 views

Why does std::function_ref allow passing in an expiring functor, rather than disallow it?

At https://en.cppreference.com/w/cpp/utility/functional/function_ref/function_ref.html, there is an overloaded ctor as follows: template<class F> function_ref(F&& f) noexcept; ...
xmllmx's user avatar
  • 44.5k
0 votes
1 answer
56 views

RDF standard ontology for statement with a start and end

I am building an application that builds SPARQL query, and I'm trying to make it as generic as possible. In my data, I need to be able to model some affiliations between people and structures. These ...
Equino's user avatar
  • 89
-1 votes
1 answer
86 views

Using true/false vs 1/0 in MongoDB Projections — Long-Term Compatibility [closed]

In our Go codebase, we’re building dynamic projection maps for queries. Instead of using map[string]int{"name": 1}, we’re considering using map[string]bool{"name": true} for ...
Aadi Sharma's user avatar
0 votes
0 answers
107 views

Why does std::equality_comparable_with not work in the simplest case? [duplicate]

#include <concepts> struct A {}; struct B {}; constexpr bool operator==(A, A) { return true; } constexpr bool operator==(B, B) { return true; } constexpr bool operator==(A, B) { ...
xmllmx's user avatar
  • 44.5k
1 vote
1 answer
114 views

Does the IOC (Implicitly Object Creation) apply to my_alloc wrapping std::malloc?

Consider p0593 and the following code: struct A { std::string s; }; static_assert(std::is_implicit_lifetime_v<A>); // true! // std::malloc is explicitly BLESSED by the C++23 standard. // But ...
xmllmx's user avatar
  • 44.5k
2 votes
1 answer
294 views

Why is it UB to pass a char array as the argument of placement new?

I think the following code is ubiquitous: struct A { ... }; char buf[1024]; auto ptr = new (buf) A(...); However, new (buf) A(...); is UB. https://en.cppreference.com/w/cpp/language/lifetime.html ...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
151 views

Why add redundant `std::constructible_from<T>` to the concept `std::default_initializable`?

At the cppref page on the concept std::default_initializable, I saw the following code: template<class T> concept default_initializable = std::constructible_from<T> && ...
xmllmx's user avatar
  • 44.5k
3 votes
1 answer
95 views

Is it allowed in javascript to modify the handler after proxy has already been created?

I modify the handler object after proxy's creation, and obtain intended result. But nowhere in mdn document such pattern, can i rely on this pattern to work consistently across browser/in future? ...
StructSeeker's user avatar
5 votes
2 answers
288 views

Why was this sentence removed from C23?

I usually referred to C17, but decided to switch to C23. And looking through the C23 standard, I saw that the sentence from C17 was deleted in C23: A declaration other than a static_assert ...
ALICEZzz's user avatar
  • 639
1 vote
1 answer
77 views

Do I need to set a CL_MEM_READ_WRITE when creating a buffer?

When creating a buffer in OpenCL, one passes a flags bitfield. One of these possible flags is CL_MEM_READ_WRITE, being the lowest bit in the field (value 1 << 0). Its documentation says that &...
einpoklum's user avatar
  • 137k
1 vote
1 answer
113 views

is using the + operator a way to remove qualifiers within the typeof operator instead of using typeof_unqual in C23?

C23 added the typeof_unqual keyword as a way to get the unqualified type of an object. Can't you just use the + operator on scalar types to avoid this? (I know this doesn't work on struct/union typed ...
Badasahog's user avatar
  • 1,025
4 votes
1 answer
112 views

Why does C++ allow std::function assignments to imply an object copy?

My question concerns the line of code below marked with the // WHY??? comment. Below is a toy example of some code I was expecting to break: a std::function variable is assigned a function pointer ...
srm's user avatar
  • 3,361
1 vote
0 answers
29 views

How should email addresses that contain / be encoded in mailto: URLs?

Which of the following should be the URL for the email address ~a/[email protected]? mailto:~a/[email protected] mailto:~a%[email protected] Although most clients are able to handle (1), is (2) required by ...
Runxi Yu's user avatar
  • 412
21 votes
1 answer
1k views

Did C++20 change to allow conversion from array-of-known-bound `type(&)[N]` to array-of-unknown-bound `type(&)[]`?

Context: In C++, it's possible to create a reference to an "array of unknown bound". Example: const char (&)[] Before C++20, clang (14.x, 18.x) did not allow you to coerce a reference to ...
Catskul's user avatar
  • 19.8k
0 votes
0 answers
60 views

Is integer overflow defined behavior in Fortran? [duplicate]

According to the C standard, signed integer overflow is undefined behavior. Fortran integers are signed integers. Does the Fortran standard mandate how overflow should be treated? In practice it seems ...
M0M0's user avatar
  • 236
0 votes
0 answers
33 views

PayPal Standard Checkout is not generating an OAuth token (PHP) [duplicate]

I'm trying to implement PayPal Standard Checkout in PHP, and when I make a server-side request, this error appears: "Following authentication credentials are required:\n-> Client is not ...
LucasAaa21's user avatar
0 votes
0 answers
121 views

Why did Stroustrup write in PPP (2nd editioln) that operator ++ does not work with type char?

I've read in Stroustrup PPP "Programming Principles and Practice Using C++", 2nd edition in table "useful operators for some common and useful types" here that type "char&...
fedya's user avatar
  • 19
3 votes
1 answer
121 views

Why is a consteval function expression NOT a primary expression?

Consider the following code snippet (compiled with clang19): consteval bool IsEven(int n) { return 0 == n % 2; } template<int n> requires (IsEven(n)) // ok void f1() {} template<int ...
xmllmx's user avatar
  • 44.5k
2 votes
0 answers
117 views

Sizeof equality of direct members vs inherited members

Does the C++ standard have anything to say about the size equality of the following? struct AB { int a; int b; } Or struct A { int a }; struct B : public A { int b; } Is sizeof(...
Boris's user avatar
  • 1,489
16 votes
1 answer
950 views

Is `std::function` deprecated by `std::copyable_function` in C++26?

C++26 provides std::copyable_function [cppref link]. However, the existing std::function is already copyable. So, I have 3 questions: What are the key advantages of std::copyable_function over std::...
xmllmx's user avatar
  • 44.5k
13 votes
1 answer
144 views

Why use `(void)++p` rather than just `++p` in this C++ standard proposal? [duplicate]

In a C++ standard proposal, I find a strange code snippet as follows: template <input_iterator I, sentinel_for<I> S, nothrow_forward_iterator I2> constexpr auto uninitialized_copy(I first, ...
xmllmx's user avatar
  • 44.5k
0 votes
1 answer
68 views

What are the Standards and The Best Practice In c? [closed]

i'm new here, i'm trying learn c and also i want to know the best practices to write good quality code and legible code, Thanks. i'm tried search the standards and best practices in c but i didn't ...
xnowvv's user avatar
  • 11
3 votes
1 answer
303 views

Is shifting 0 to the left considered undefined behavior in C?

Is either of these expressions Undefined Behavior (UB)? 0 << 32 0LL << 64 I would appreciate it if the answer includes references to the C standard.
lol lol's user avatar
  • 531
0 votes
1 answer
74 views

Standard Method of Supporting Vendors Using C++ and Premake

I am working on a template that makes use of Premake and GoogleTest, but I am having issues finding any documentation on a standardized method of implementing Premake. The source that I have been ...
Jayden Campbell's user avatar
3 votes
1 answer
172 views

C standard - const qualification of struct members

I encountered a problem at work today regarding const propagation in structs. I was trying to add some const correctness to old code when I ran into an issue where two different compilers disagreed, ...
sljung's user avatar
  • 41
0 votes
1 answer
63 views

Difference between chr and Char.chr in Standard ML

My program: val a = chr 65 : char val b = Char.chr 65: char val _ = print (Char.toString a) val _ = print (Char.toString b) Output: AA Lines 1 and 2 show that both chr and Char.chr work. Is there a ...
Lone Learner's user avatar
  • 21.2k
5 votes
2 answers
210 views

Regarding POSIX ERE's new ? modifier with nested repetitions

The 2024 version of POSIX specifies the ? repetition modifier. In the published document, it's specified that the ? modifier changes the behavior of its immediately preceeding repetition from matching ...
DannyNiu's user avatar
  • 1,671
1 vote
0 answers
72 views

MIDI spec: "respond accordingly" to missing LSB or MSB of parameter number

What does the MIDI 1.0 Detailed Specification mean by "respond accordingly" to receiving only a least-significant byte (LSB) or a most-significant byte (MSB) (but not both) for a (non-)...
root's user avatar
  • 2,946
3 votes
0 answers
156 views

Did ISO C++ make any attempt to standardize `unsafe {}` blocks/functions/namespaces in the language?

The unsafe keyword is a relatively familiar language feature, known mostly from C# and Rust. The general idea of the feature is to define "safe" subset and then require demarking any usage ...
user7610's user avatar
  • 29.9k

1
2 3 4 5
69