this post was submitted on 31 Jan 2025
8 points (83.3% liked)
C++
1848 readers
10 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm unsure if that's even possible in C++ for a "normal program" instead of requiring a full-fledged compiler and even maybe a linker, as C++ syntax is completely context-dependent. There's no way to tell if
i+=b;
increments a value or is actually a dynamic hierarchy cast that prints a message to screen and invokes a vector copy with data downloaded from the internet.I'd venture there's something in Clang that does this? (clang-tidy, clang-format, who knows), since they implement the syntax tree parser thing.
I didn't even think about how context dependent C++ is until you mentioned that. That's a really good point
Yeah basically C++ is fun (or "fun") in that in order to try and get what code does or what it means you have pretty much no other alternative than trying to compile it.
There are a number of terms that have only one meaning and can appear in only one "semantic place", such as
namespace
,return
and... I think that's it? Maybe (maaaaybe).*
. So it's little enough that doesn't give you that much good information if you try and hand-parse them out from the code you have.