Most active questions

14 votes
3 answers
2k views

Why is it ok to cast to an undeclared struct pointer in C?

Why does this code compile? struct test is not even forward declared. int main(){ *(int*)((struct test*) 0x1234) = 0x0; return 0; }
Dan's user avatar
  • 3,038
13 votes
1 answer
1k views

Is it safe to catch stack overflows? Can it leave objects in messy/intermediate states?

I've been reviewing ways to kill threads in Java, and the overwhelming conclusion is that it is never safe to stop code at arbitrary points - doing so may leave resources in messy intermediate states. ...
Edward Peters's user avatar
11 votes
1 answer
570 views

MSVC calls wrong virtual method when storing a pointer to virtual method in a static inline variable

I'm encountering unexpected behavior on MSVC when storing a pointer to a virtual method in a static inline variable. The issue does not occur on GCC or Clang. Specifically, when I store a pointer to a ...
Artem Selivanov's user avatar
4 votes
5 answers
118 views

Assign a number for every matching value in list

I have a long list of items that I want to assign a number to that increases by one every time the value in the list changes. Basically I want to categorize the values in the list. It can be assumed ...
Regina Phalange's user avatar
9 votes
1 answer
261 views

What explains pattern matching in python not matching for 0.0, but matching for float()?

I would like to understand how pattern matching works in python. When I use matching with a type like float(), it matches 12.0, but when I use it with 0.0, it doesn't. I wonder why. I am new to ...
mvallebr's user avatar
  • 2,620
6 votes
1 answer
176 views

Assignment in (else) if statement triggers warning in MSVC but not in gcc / clang

This code snippet triggers a warning in MSVC (VS2022 17.10.2). int m = 0; if(int i = m) // ... else if (int i = m) // warning C4456: declaration of 'i' hides previous local declaration // ... ...
Lars's user avatar
  • 71
10 votes
1 answer
235 views

Why can this C++ code pass compile check? [duplicate]

I accidentally added a semicolon in an expression constructing std::string, but the compiler happily accepted it without complaining anything. I did a minimum reproducible example below, kindly teach ...
PkDrew's user avatar
  • 1,379
1 vote
4 answers
246 views

std::vector: when is a pointer not a pointer?

I have this existing working code, which I am trying to convert to implementation: Bitmap *pbitmap = new Bitmap(L"images.png"); nWidth = pbitmap->GetWidth(); nHeight = pbitmap->...
Gorlash's user avatar
  • 69
3 votes
2 answers
102 views

C++: `if constexpr` and `std::is_same_v` not working

I'm playing around with templates, compile-time evaluation and pointers to members. I don't understand why the following code doesn't set a.x to 42 and a.y to 3.14. According to the output, FieldType ...
md2perpe's user avatar
  • 3,113
20 votes
1 answer
1k views

CoreWCF stream continues to be written to after client disconnects

I have a very simple service class: using System.Diagnostics; var builder = WebApplication.CreateBuilder(); builder.Services.AddServiceModelServices(); builder.Services.AddServiceModelMetadata(); ...
Eterm's user avatar
  • 2,025
3 votes
3 answers
127 views

How do you convert a single surrogate character without a pair into its UTF-8 equivalent?

I am experimenting with wctomb in order to convert a wchar_t into its UTF-8 equivalent stored in a char[]. It works nicely, but not for surrogate characters ranging U+D800 to U+DFFF. int ret; // null-...
amegyoushi's user avatar
0 votes
2 answers
177 views

Invalid comparator in std::sort due to correct same result in both orders

I'm sorting a vector of structs, std::vector<DRIVE_OR_DIR>, where DRIVE_OR_DIR is defined as typedef struct { std::string path; boolean isDrive; } DRIVE_OR_DIR The idea is that elements ...
gene b.'s user avatar
  • 12.2k
2 votes
2 answers
201 views

Loop on objects of different types

Consider this code (there are many more ReadJSONkey lines in the real code): int LoadParametersFromJSON(JsonDocument& JsonDoc) { int err = 0; err += ReadJSONkey(Pins, JsonDoc, "Pins&...
fakbill's user avatar
  • 23
1 vote
2 answers
164 views

How to declare static constexpr variable in C++?

I have a Foo class that includes an array and a static constexpr variable. As a general convention, I want to write public and private variables respectively. But, compiler error occurs 's_array_size' ...
unique's user avatar
  • 127
2 votes
4 answers
89 views

How to functionalize base R function like `with()`?

I am trying to write a function that operates similarly to with() where the function has a data argument, and two other arguments that I would like evaluated in the context of the data frame. I ...
Daniel D. Sjoberg's user avatar

15 30 50 per page
1
2 3 4 5
280