Most active questions
924 questions from the last 7 days
Best practices
8
votes
27
replies
2k
views
Moving from C, how can I implement a doubly linked list in C++ using C++ features?
I'm moving from C to C++ and I'm trying to avoid using C practices in C++.
It is said that raw pointers are a C feature, and that in C++ I should use smart pointers instead, yet every example I have ...
11
votes
5
answers
1k
views
Finding an operator for 3 distinct values with bitwise operations
Consider the set {A,B,C} and an operator op defined by the following table
A op A = A
A op B = A
A op C = A
B op A = A
B op B = B
B op C = C
C op A = A
C op B = C
C op C = B
I would like to encode A,...
12
votes
4
answers
1k
views
Why don't C overflow checks use CPU flags?
Both amd64 and arm64 architecture processors have an overflow flag. However, in C, the most common method to detect whether an operation causes overflow/underflow is to make functions like these:
int ...
Advice
2
votes
11
replies
388
views
I can't understand structure padding in C/C++
I watched a few tutorials on YouTube. They said to assume a 32-bit architecture and then said "a single CPU cycle can only access a word (equals the CPU's native size i.e 4 bytes) at a time from ...
Advice
1
vote
17
replies
195
views
Surprising behaviour of using static_cast on struct with bit fields
The following code compiles on std >= C++20 but fails to compile on std < C++20. This holds for msvc, gcc and clang.
#include <cstdio>
int main()
{
struct byte
{
unsigned ...
Best practices
2
votes
5
replies
151
views
Forwarding C-style struct matrix to constructors of same-size matrix of objects
Suppose I have a C-style matrix of elements
typedef struct _RAW_DATA{
int a;
int b;
}RAW_DATA;
inside a templated class, that defines the size of the matrix:
template<size_t TDim>
...
2
votes
2
answers
145
views
How to avoid implicit conversion in C++ concepts?
Is there a way to prevent implicit conversions happening in concepts? For example, this example compiles with GCC and clang when I actually want it to give an error that the char constructor is ...
3
votes
2
answers
164
views
C Struct Passed By Value Memory Addresses in Called Function
I've seem to run into something I can't really explain. I'm testing out passing a struct (typedef with an alias) by value into a function and printing out the addresses of each. I do realize that ...
0
votes
3
answers
140
views
PHP, $regex to obtain each URL of videos about $pattern
I try with some regex to obtain only the URL of all the videos about $pattern but my $regex not work (in this case $pattern = "Greta"):
$data = '<p><a href="https://www.youtube....
1
vote
2
answers
363
views
What impediments are there to inclusion of the Networking TS in the C++26 standard?
As C++26 standard's timeline is getting near, I want to know:
What is(are) the reason for no built in support of networking by the C++ standard. That is, what exactly are the problems that lead to ...
4
votes
4
answers
123
views
Changing column values based on values of separate columns
I'm trying to figure out how to change values in a column (Age), based on the values of two separate columns (Species and Length).
I have a dataset of fish lengths, with all of them designated either &...
Advice
2
votes
7
replies
119
views
Compund literals as struct initializers
Let's consider this example code:
#include <stdint.h>
#include <stdio.h>
struct image {
int width, height;
uint8_t *pixmap;
};
static void iprint(const struct image *img)
{
...
Advice
0
votes
5
replies
128
views
Understanding a Component of a C Function Declaration
I am reviewing an application and it has numerous functions with the following function declaration. I've never seen this type of function declaration with the "local" identifier before the ...
0
votes
4
answers
188
views
Synchronized method and access with another thread [duplicate]
When one thread is blocked in a synchronized method of an object, does another thread have access to that object through the same or another synchronized method?
Actually, will my thread be blocked if ...
Advice
0
votes
7
replies
127
views
PHP shorthand for isset && truthy
Is there a shorter way to write the following in php?
$bar = isset($foo['bar']) && $foo['bar'];
or
$verylongname = isset($_POST['verylongname']) && $_POST['verylongname'];
I'm using ...