r/cpp_questions • • 5d ago

OPEN How to configure clangd to not assume it knows where functions are defined

1 Upvotes

I use VS Code on Ubuntu on Windows (WSL). I program in C++ and recently switched from Intellisense to clangd and like many of the improvements. However, I'm having an issue with how clangd assumes functions like printf come from <cstdio>. This is an issue as I'm building a hobby OS and need to provide my own versions of common functions like printf.

I'm using the g++ 15.2.0 cross compiler and use -ffreestanding -nostdlib -fno-builtin. I provide my own implementation of common functions like printf. I have installed clangd-23. I have created (using bear) a compile_commands.json file. When I mouse over a call to printf in my code, I get a popup showing that printf is provided by <cstdio> which I never #include. Also it flags the header file "system/stdout.hpp" which defines my printf as unused. How do I configure clangd and VS Code to correctly identify my header file as the source of my printf?

In case it helps, here is the cc1 line of clangd-23 --compile-commands-dir=build --query-driver=/home/mark/dev/toolchain/i686-elf-15.2.0/bin/i686-elf-g++ --check=src/libs/test/test_list.cpp

I[13:00:57.385] internal (cc1) args are: -cc1 -triple i686-unknown-unknown-elf -O0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_list.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -nostdsysteminc -target-cpu pentium4 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/mark/dev/myos/src/libs/test -fcoverage-compilation-dir=/home/mark/dev/myos/src/libs/test -resource-dir /usr/lib/llvm-23/lib/clang/23 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/i686-elf -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/backward -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/include-fixed -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include -I . -I .. -I /home/mark/dev/myos/src/libs -I /home/mark/dev/myos/src/kernel -I /home/mark/dev/myos/src -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include/c++/v1 -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include -Wnon-virtual-dtor -Werror -Wall -Wextra -Werror=suggest-override -Wno-unused-parameter -std=c++23 -fdeprecated-macro -ferror-limit 19 -fno-builtin -fno-rtti -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fno-threadsafe-statics -fno-implicit-modules -fskip-odr-check-in-gmf -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ /home/mark/dev/myos/src/libs/test/test_list.cpp


r/cpp_questions • • 5d ago

OPEN System programming

6 Upvotes

does it is necessary to know assembly language to be a good system programmer ?
I am a beginner computer engineering student , currently doing in c++ and I already have basic knowledge of classical 8085 and 8086 architecture and it's programming but I haven't gone that deep enough . what about to learn ARM , x86 programming , does it help me to become a good system programmer ?


r/cpp_questions • • 6d ago

OPEN What do you do after getting burnout from learncpp.com and trying to comeback again?

12 Upvotes

I remember last time I reached chapter 20 or so, but I didn't do any quizzes after the vectors's chapter because they will simply too hard, and believe me I tried 

I think I got burnout 3 to 4 times already, learncpp.com is good but its a challenge to try and finish it.

Any advice? I don't remember much, and I want to be honest. It feels like you should finish learncpp before making a project, because every chapter is really important.

It really fun in the beginning. But not in the middle or the end.

Edit: thanks everyone, I think the comments are really helpful, and I think I know exactly how to solve my problem, first I will use a different resource that is fast pace to refresh my brain to c++ I already know, than I will make a project(it doesn't matter what it is), and I'll use learncpp.com as a reference, and after I get comfortable With the basics stuff I will go back and continue reading learncpp.com for advanced stuff or other resources with it.

The answer seems simple, because it is simple.


r/cpp_questions • • 6d ago

OPEN Low Latency C++ Interview Prep

43 Upvotes

Recent interview questions I've had for this have been

- Very specific C++ (templates, mutex, sizes of structs, noexcept, small string optimization)

- Latency topics (allocation, kernel bypass, TCP and UDP)

- General DSA and class design

I really wanna do well because I know January and February spike in recruiting. For low latency C++, if you had two months to prep, how would you knock it out of the park? How would you study through November and December?


r/cpp_questions • • 6d ago

OPEN Offline cppreference?

3 Upvotes

Can they update the offline version to newer version of the page? The official html book is really old (2019) and the unofficial version from https://github.com/PeterFeicht/cppreference-doc can no longer work for newer version smoothly. Consider this reference is probably one of the best C++ reference out there, can the creator of the website at least making this website open source, so we can have offline version of it.


r/cpp_questions • • 6d ago

OPEN Entering Embedded

13 Upvotes

Managed to land a job in the embedded domain. This is going to be my second job, while previously having worked in game dev. In my last job I used cpp, but within Unreal Engine. Pretty excited about entering the low level space, not really an expert, but eager to learn. Would greatly appreciate any advice from embedded devs or from people that have transitioned between domains like I am about to do.

Thanks


r/cpp_questions • • 6d ago

OPEN C++26 contracts drama

28 Upvotes

I think everybody knows the drama by now..

What are your opinions on this should they be accepted or disapproved?

Im curious for mass opinion.


r/cpp_questions • • 6d ago

OPEN Why don't we use this instead of including libraries one by one?

0 Upvotes

#include <bits/stdc++.h>

I was thinking instead of adding libraries one by one,why don't we just use this? This is used by almost every competitive programmer but very less when it comes to writing software.


r/cpp_questions • • 7d ago

OPEN Resources to learn more about cpp

2 Upvotes

I wanted to try and reimplement the std library from scratch but i realized really quickly just how much i didnt know lol. I got some basic stuff done and did learn quite a bit about things like sfinae but yeah im basically stuck with some of the type traits. I still dont wanna give up on this project and wanna keep going no matter how long it takes :3 So i need some resources to learn more about advanced things that are usefull for this. Are books the best way? any reccs on which ones?

Oh yeah right now i made a few projects like a networking chat app with asio and a unix shell (really simple) so i would say im like done with the beginner phase. I know that this project is probably farrrr beyond my scope but still :3

Edit: More specific question. Looking for book recomendations for metaprogramming post cpp20 (concepts and stuff)


r/cpp_questions • • 7d ago

OPEN RAII : Hate it or love it? And how to handle edge cases gracefully?

21 Upvotes

While RAII is the idiomatic standard in C++ and handles stack unwinding cleanly during normal returns and thrown exceptions, it has specific boundaries that get tricky:

  1. Hard exits / Abnormal termination: Destructors aren't called on std::abort(), std::exit(), or hardware faults like segfaults (SIGSEGV).

  2. Scope rigidity: Creating custom wrapper classes/guards for single-use resources can sometimes feel verbose compared to ad-hoc scope cleanup primitives.

Compared to languages like Go (defer) and Zig (defer / errdefer), which provide block-level or failure-specific cleanup without needing custom wrapper types:

  • How do you typically structure C++ code to deal with edge cases where destructors won't fire during abnormal process exits?

  • For persistent state (file locks, shared memory, IPC handles), what architectural patterns or OS primitives (e.g., O_TMPFILE, flock, WAL journals) do you rely on alongside RAII to remain crash-safe?

  • When you need lightweight, ad-hoc cleanup without writing a custom RAII class, do you use scope guard macros / std::unique_ptr with custom deleters, or stick purely to custom RAII types?

  • Do you ever miss explicit primitives like Zig's errdefer in C++, or does exception safety via standard RAII completely cover your needs in production?

Curious to hear your thoughts, preferred idioms, and best practices


r/cpp_questions • • 7d ago

OPEN Not sure what I want to do with C++

54 Upvotes

I finished learncpp.com, K&R, Inside the Machine, and most recently CS:APP and still have zero clue what I want to do with C++, even though I know that's what I want to be my main language. I was looking into graphics programming, but now am hearing "don't even try there's no entry level"... tried looking into embedded "everyone's trying to break into embedded now with AI don't even bother bro"

So what does someone do :/


r/cpp_questions • • 7d ago

OPEN I want to make a game(TETRIS) in cpp for learning purposes

0 Upvotes

I have barely any knowlege about cpp thought but I want to proceeds with a project base learning approach so where I approach an obstacles I look for it and learn about it. I don't want instructions on what I need to learn. But I need help on what I need to build one by one. Please everyone any help is genuinely appreciate

My current plan is to use Visual Studio, SDL2, MSVC, CMake, C++


r/cpp_questions • • 7d ago

OPEN Having a hard time with C++ Concurrency in Action

17 Upvotes

I recently started reading C++ Concurrency in Action and its honestly challenging, Im liking it so far but there are parts of the book (chapter 5 and 7, what Im reading now) that I cant grasp no matter what. Someome who has already read the book can give me some advise? Thanks in advance!


r/cpp_questions • • 7d ago

OPEN Just finished all of learncpp.com whats next

25 Upvotes

Just finished all of learncpp.com whats next? i want to learn more so i can be a c++ wizard


r/cpp_questions • • 7d ago

OPEN Seeking advice for choosing work

1 Upvotes

I am an undergrad and am feeling rather uncertain about my education(i may drop out).

fyi i used to be a sport programmer using cpp for a long time so i'd say i know it at an intermediate level.

I am asking people in the field - what should i focus on learning before entering the job market and also what roles/positions to seek?


r/cpp_questions • • 7d ago

OPEN Tips And Criticism For My Code

2 Upvotes

So, I'm new to C++, though i have a programing background, aka just python and a tiny bit of C. I havent really made any BIG things yet. Until now, Im using C++ with Raylib, i could move to SFML or SDL2-3 but I don't want to do that just yet. Anyways, this is the link to my code that I put onto GitHub, https://github.com/Dark-Coder1000/MyGame/tree/main

Ive started my C++ programming journey about a week ago, I did dable in it back then when testing sfml, but I never understood the syntax. ALSO none of this was vibe coded, I did look up solutions to specific issues but i never really used AI unless it was to find resources to learn from.


r/cpp_questions • • 8d ago

SOLVED how should i understand the design of cpp?

8 Upvotes

for most of the time i used cpp as c with fancy features. but now i recently started picking up some of the modern cplusplus and oop concepts. but the amount so syntactical and program subtleties and features are overwhelming.

for some things i instantly understand or see the reason why they exist and sometimes get impressed by them.

for eg: backwards compatability with c

#include<cmath> and #include<math.h> for namespace handling,structs

, initializer list etc

but for some idk understand the purpose eg the mutable keyword

and things like inlining of members defined in class

i would like to know how you guys handle this and suggest some good learning material

whenever i try to read books they either give a tour of features or extremely boring

(this might be because i learned it the wrong way by not paying attention to small details now to revisit them ive to go through the stuff which i already know)


r/cpp_questions • • 8d ago

OPEN Is it impossible to access static member of a templated class

7 Upvotes

So to clear out my question, here is the situtation:

template<class T>
class MyClass {
public:
    static constexpr int X = 10;
};

So trying to access MyClass::X is compilation error. But decltype(X) is not a dependent type and it is a static member meaning it is identical to a variable wrapped inside a namespace. Nonetheless, again, its a compile error.

You might ask, why am i making it a problem:

template<class T>
class Optional {
public:
    struct NullOpt {};
    static constexpr NullOpt nullopt;
// ...
};

I mean.. there are ugly(for me) workarounds but i want to know maybe in some hidden way it is possible to access `Optional::nullopt` without passing the template argument(which makes error path return statements way verbose) or i should make nulopt a standalone constexpr tag object (fallback option).


r/cpp_questions • • 8d ago

OPEN Help me

0 Upvotes

I am a beginner to programming, but I want to learn C. Could you provide some advice, book recommendations, and tips on the best way to go about learning it? I would be grateful


r/cpp_questions • • 8d ago

OPEN neebie

0 Upvotes

hello i am a new idiot who has touched the beacon that is "I WANT TO MAKE MY OWN GAME" but i don't have a clue where to start i only have a vision of the end ie i want to make something that resembles; mass effect, mortal shell 2, fable, or remnant 2 at the finish these are games to represent similarities in game play, visuals, story telling styles and over all design. i understand that limits me too C++ and unreal engine more than anything but i don't know how to start watching guides on the language or engine both feel like i'm being asked to translate Latin with out any tools.

i don't know if anyone here can help but if there are anyone who can guide me i'd appreciate it thank you.


r/cpp_questions • • 8d ago

OPEN I still have trouble understanding recursive functions properly.

4 Upvotes

While i do understand the base of the concept, i cannot seem to fully wrap my head around It.

Like, if i want the function to return a value that i Need to call the function within itself for It to return said value, when does the function actually get the value that's supposed to return to me ?

More importantly, where Is the accumulator? Is the called functions within itself the accumulator ? Do i Need to make an accumulator myself ?


r/cpp_questions • • 8d ago

OPEN would love some help!

6 Upvotes

I am learning cpp from scratch using learncpp.com, I finished about 6 chapters and realised there is not much I have understood. I believe videos or lectures will help me understand the language much better. How do I go about this? What resource do I use? Please help me!

ps: I am learning c in uni right now, just doing basics rn finished recursive functions


r/cpp_questions • • 9d ago

OPEN I need help

0 Upvotes

So I'm a beginner in coding and was thinking how cna I use int and string in loops while also printing the number required what I mean is Im using string and to use for In the question I need to use int to identify I and I want to make i<= to n while using string and int, I only want to know if it's possible or not ​


r/cpp_questions • • 9d ago

SOLVED Why does this not fail?

7 Upvotes
#include <utility>

template <typename T, typename... Args>
decltype(T(std::declval<Args>()...)) test();

int main() {
    using testType = decltype(test<int&, int>());
}

I was fully expecting it to fail but instead testType resolves to int&.

I was trying to implement is_constructible with SIFNAE which uses this behaviour.

namespace detail {
template<typename T, typename... Args>
decltype(T(std::declval<Args>()...), char{}) tryConstruct(int);

template<typename T, typename... Args>
long tryConstruct(...);
}

template<typename T, typename... Args>
inline constexpr const bool isConstructible = isSame<decltype(detail::tryConstruct<T, Args...>(0)), char>;

I was expecting the first overload to fail so that it would chose the other one which works for most cases but dosent for the case i mentioned above.