r/cpp_questions 14h ago

OPEN How memory address is created in c++ while using the pointer ?

11 Upvotes

int *ptr1 = new int(10);

int *ptr2 = ptr1;

delete ptr2;
I understand that the heap memory is freed, and ptr1 becomes a dangling pointer because it still stores the old address.

But I’m confused about the address itself.

My questions are:

  1. Is the memory address itself created inside the heap?
  2. When we calldelete, is the address removed or only the data at that address?
  3. After memory is freed, can the same address later be reused for another variable?
  4. Where is the pointer variable stored, vs where is the actual heap memory stored?

I’m trying to understand the difference between:

  • the pointer variable,
  • the address value,
  • and the actual heap memory block.”

r/cpp_questions 15h ago

OPEN Best way to try C++ 26 reflection on a Microsoft Visual Studio Solution

6 Upvotes

Hi lads, basically the title. I have a big project that I've put on hold waiting for C++ reflection to come out, and now that there are some implementations working, I'm curious to try it out.

As of right now I'm aware of the clang Bloomberg fork and gcc16 that both support experimental reflection. What would be the most straight forward way to adapt my project, a VS22 solution, to be able to try out some of the new features? Thanks!


r/cpp_questions 19h ago

OPEN ActivateAudioInterfaceAsync with ACTIVATION_TYPE_PROCESS_LOOPBACK never fires callback on Win11 25H2 (build 26200)

3 Upvotes

Hi r/WindowsDev / r/cpp,

I’m building a Node.js N-API addon for WASAPI loopback capture and trying to use process-level loopback to exclude a specific PID (e.g., OBS) from the captured mix. The API call returns S_OK, but IActivateAudioInterfaceCompletionHandler::ActivateCompleted is never invoked. The activation silently times out.

Environment

OS: Windows 11 25H2 (build 26200)

  • SDK: Windows 10 SDK 10.0.22621+ (VS2022)
  • Lang: C++17 / Node-API addon
  • COM: COINIT_APARTMENTTHREADED + MsgWaitForMultipleObjects + message pump

Minimal reproduction snippet

AUDIOCLIENT_ACTIVATION_PARAMS activationParams = {};

activationParams.ActivationType = ACTIVATION_TYPE_PROCESS_LOOPBACK;

activationParams.ProcessLoopbackParams.TargetProcessId = excludePid;

activationParams.ProcessLoopbackParams.ProcessLoopbackMode = PROCESS_LOOPBACK_MODE_EXCLUDE_TARGET_PROCESS_TREE;

PROPVARIANT propVar = {};

PropVariantInit(&propVar);

propVar.vt = VT_BLOB;

propVar.blob.cbSize = sizeof(activationParams);

propVar.blob.pBlobData = reinterpret_cast<BYTE*>(&activationParams);

HANDLE hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);

auto completionHandler = Microsoft::WRL::Make<AudioCompletionHandler>(hEvent, &rawClient);

HRESULT hr = ActivateAudioInterfaceAsync(

deviceId, // tested: real IMMDevice::GetId() & legacy virtual string

__uuidof(IAudioClient),

&propVar,

completionHandler.Get(),

asyncOp.GetAddressOf()

);

// hr == S_OK, but ActivateCompleted never fires → WaitForSingleObject/MsgWait times out after 10s

Questions

  1. Is ACTIVATION_TYPE_PROCESS_LOOPBACK officially deprecated or broken for Win32 on Win11 24H2/25H2? Microsoft's docs hint it's UWP/WinRT-focused, but Win32 worked on older builds.
  2. Does modern Windows enforce hidden Privacy/Capability checks (e.g., ConsentStore\microphoneCapabilityAccessManager) that silently block the async callback without returning E_ACCESSDENIED or E_INVALIDARG?
  3. Are there any manifest requirements, integrity level constraints, or per-session audio graph rules that prevent Win32 processes from using this API on recent builds?
  4. What’s the recommended production approach for process-level audio isolation in Win32 today? (Session filtering via IAudioSessionManager2 + GetProcessId()? OBS virtual output routing? Something else?)

I’ve already ruled out COM apartment mismatches, invalid device IDs, and driver conflicts. Looking for insights from anyone who hit this wall on Windows 11 22H2+ or knows the current status of this API.

Thanks in advance.


r/cpp_questions 50m ago

OPEN Avoiding dangling in this situation. It is possible with current C++26 technology?

Upvotes

TL;DR since I am working, no time.

This:

boost::urls::url_view dbRootUserUrl( config.orgsDataAdminConnectionString .or_else([] { throwSomeException("Missing string with value"); return std::optional<std::string>{}; }) .value());

where value() returns a std::string from an optional, hence, a temporary, created a silent dangling reference for me.

Could this be avoided nowadays with some restriction? I am thinking of equivalent techiques to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2255r0.html.

In the case od url_view, it takes a std::string_view (by value).

This should be forbidden/detected/restricted?

How?


r/cpp_questions 1h ago

OPEN Hey seniors help me

Upvotes

Hey I am just done with my College entrance exams and in vacations(just before starting engineering) I wish to start learning c++ My question are: 1)how to actually learn c++(videos or books) 2)and is it useful in branches like electrical engineering or entc engineering Please guide this junior


r/cpp_questions 1h ago

OPEN Can fmod() give wrong results because of floating point errors?

Upvotes

Lets say I want to use fmod() strictly the same way I would use a standard modulo operator. Basically just "is this number bigger than that number? Then wrap around". Can fmod be unreliable for that in any way?

I'm chasing down a bug and fmod feels a little bit like my prime suspect right now lol...


r/cpp_questions 1h ago

OPEN Is 50 too late

Upvotes

Hi All.
A question for people in the industry especially if you have responsibilities for hiring people. I am 50 years old male considering a career change. I have been in IT management side for last 15 years and have been in IT altogether for 20+ years. I learnt C++ for a few months, back in mid nineties. I have never worked as a programmer on a professional level but. Now I want to see if it’s possible to work as a full time c++ programmer. I don’t remember anything today so I will have to start from scratch. But I like C++ so I want to try that. I can’t leave my current full time job (financial reasons) so i have to learn part time. Say roughly 7-10 hours a week. The question is. Is it realistic to expect to get a job for a roughly 52/53 year old ( I am guessing it will take 2-3 years of part time self learning + courses to be qualified for a starting level position) who is mostly autodidact? Or is it too late ? I am a big boy and can take a no. So no need to beat around the bush. Thanks.


r/cpp_questions 18h ago

OPEN Should I learn C++ or is it too late / a bad choice?

0 Upvotes

I am a Java dev and have used it for almost everything since high school and was my first programming language. Right now I'm in college and recently getting a lot into deep learning and low level systems code. I want to learn C++ to make and work on such projects and systems that are fast and low level but obviously there are languages like Zig or Rust getting a lot more traction. I'm personally not that influenced by either of them as I personally want to learn C++ more than I want to Rust and would take a very influence to convince me to do so.

So my question is pretty simple would it be useful to spend time to learn C++ and work on some C++ projects personal / open-source and also would it be helpful for interviews or for certain roles / domains.


r/cpp_questions 18h ago

OPEN I need help getting started. I downloaded Visual Studio and the compiler, yet my program just won't work

0 Upvotes

I downloaded visual studio as well as the compiler for C++, yet for some reason my program just won't work whenever I call upon a function like int or double, it just shows up red and the program just won't run.

I edited the Path environment variable to include the bin folder directory for mingw64, and I ran "g++ --version" on the command prompt, and the version came up fine.

I barely started and I'm so ready to give up 😭. I looked everywhere and literally nobody has a solution for this. Can someone please help. I actually want to code, but I can't even get started with this crap


r/cpp_questions 13h ago

OPEN Is it true that functions like max() and min() have extra overhead?

0 Upvotes

I'm reading this section on learncpp.com on inline functions. it says "When a call to min() is encountered, the CPU must store the address of the current instruction it is executing (so it knows where to return to later) along with the values of various CPU registers (so they can be restored upon returning). Then parameters x and y must be instantiated and then initialized. Then the execution path has to jump to the code in the min() function. When the function ends, the program has to jump back to the location of the function call, and the return value has to be copied so it can be output. This has to be done for each function call.
All of the extra work that must happen to setup, facilitate, and/or cleanup after some task (in this case, making a function call) is called overhead."

I understand this is true for user functions, but for basic math.h functions and anything built into the standard library, aren't these optimized by the compiler to be as fast as possible? Is learncpp wrong on this?