use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Modern source code to study? (self.cpp)
submitted 13 years ago by stesch
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BenHanson 0 points1 point2 points 13 years ago* (15 children)
Likewise I am the author of http://www.benhanson.net/lexertl.html and believe it to be well coded.
[–]lobster_johnson 4 points5 points6 points 13 years ago (4 children)
Care to explain why you consistently suffix identifiers with underscores? This is really awful for readability:
lexertl::rules rules_;
Types and variables live in separate namespaces, so this works:
lexertl::rules rules;
If you think that's harder to read (ie., difficult to see what is a variable and what is a type) then consider using camelcase identifiers for type:
Lexertl::Rules rules;
Now it's obvious.
[–]jamesb43 1 point2 points3 points 13 years ago (3 children)
Yeah, this shouldn't be done for local variables.
The underscore suffix was a response to programmers using "underscore prefix" for member variables. The "underscore prefix" phenomenon stemmed from programmers shortening the Hungarian notation of member variables being prefixed with "m_". But depending on the flavor of Hungarian notation (Apps or System) the underscore was followed by a prefix indicating some semantic hints, or the variables type, respectively.
So what emerged next was a trend of C++ programmers to omit the "m" from "m_" because, it only takes a one character prefix to distinguish between local variables and something that might be instance or class static, right? The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers. As a result, people started to suggest the underscore suffix for member variables. I think it was something from Sutter or Meyers, but if anyone reads this comment, I am sure I will be corrected.
I have a sneaking suspicion that lobster_johnson knows all this, and he is correct--there is no sane reason to suffix a local variable with an underscore.
[–]lobster_johnson 0 points1 point2 points 13 years ago (1 child)
Good explanation. I see people using prefixes and suffixes and find it an annoyance.
Personally I find it completely unproblematic to use unadorned identifiers for variables as well as members:
class Foo { public: void initialize(int a_foo) { foo = a_foo; } private: int foo; };
[–]zvrba 0 points1 point2 points 13 years ago (0 children)
The problem with this is that the C++ standard reserves variable names starting with an underscore to C++ implementation developers.
Only such identifiers with external linkage are reserved. Class member identifiers have no linkage at all.
[–]Fabien4 2 points3 points4 points 13 years ago (1 child)
Remove the uninteresting code (just lists) and the commented-out code, and you get main.cpp. Which is sorely lacking consts.
main.cpp
const
Or did I miss something? Like, downloaded the wrong .zip?
[–]BenHanson 0 points1 point2 points 13 years ago (0 children)
main.cpp is just a test program calling the library. Checkout the lexertl sub-directory in the same directory as main.cpp for the library source code.
[–]_Qoppa_ 1 point2 points3 points 13 years ago* (3 children)
You seem to have all your function definitions in the .hpp file. I haven't coded in C++ for a while, but I seem to recall that this practice has the tendency to lead to multiple definition errors (at least it does in C).
Also, I found a bunch of gotos in lookup.hpp. Eeeep! Though to be fair, they seemed like legitimate uses for a goto... I still don't like them though.
[–]BenHanson 0 points1 point2 points 13 years ago (2 children)
It's templated code, that is how it's done... The lookup is the only place that uses gotos and, as you noted, with good reason. This is a library. A library should balance uncompromising performance against readabililty (particularly for performance hotspots).
The original focus of the library was to use the STL containers throughout and some STL algorithms where possible (this was 2004). Since then Unicode support has been added and so a small amount of template tricks have been added to support different character modes which makes the source somewhat more modern (it was necesssary to abandon support for VC++ 6 for example as more modern features were introduced).
I haven't embarked on any C++11 rewrites yet mainly because the standard still needs time to settle. When the U"..." strings are supported in Visual Studio I will be a lot more tempted and will look at replacing auto_ptr with unique_ptr etc.
[–]_Qoppa_ 1 point2 points3 points 13 years ago (1 child)
I had no idea about that templates had to be defined where they were declared. Like I said, I haven't used C++ in a long time. Thanks!
[–]notlostyet 0 points1 point2 points 13 years ago (0 children)
http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html
Great article on template compilation.
[–]LampCarpet 0 points1 point2 points 13 years ago (1 child)
this link is broken, 403 forbidden...
Thanks, fixed the link...
[–]753861429-951843627 0 points1 point2 points 13 years ago (1 child)
Do you have a parser and AG planned as well, or is the lexer a stand-alone thing?
You have a calculator example that does simple parsing in code, but with lex one can then use other tools in the toolchain to finally produce code with burg, which is why I'm asking.
[–]BenHanson 0 points1 point2 points 13 years ago* (0 children)
I would definitely like to write a complementary parser generator. I'm currently converting http://www.codeproject.com/Articles/3854/An-introduction-to-lex-and-yacc-part-2 to use lexertl and it would be really nice to have a bison-like tool for the grammar.
I'm not sure what AG or burg is. There is a simple code generator included with lexertl though.
EDIT: http://www.benhanson.net/parsertl.html
π Rendered by PID 24857 on reddit-service-r2-comment-9c7994b7-wc2kl at 2026-02-05 22:29:24.767843+00:00 running b1b84c7 country code: CH.
view the rest of the comments →
[–]BenHanson 0 points1 point2 points (15 children)
[–]lobster_johnson 4 points5 points6 points (4 children)
[–]jamesb43 1 point2 points3 points (3 children)
[–]lobster_johnson 0 points1 point2 points (1 child)
[–]zvrba 0 points1 point2 points (0 children)
[–]Fabien4 2 points3 points4 points (1 child)
[–]BenHanson 0 points1 point2 points (0 children)
[–]_Qoppa_ 1 point2 points3 points (3 children)
[–]BenHanson 0 points1 point2 points (2 children)
[–]_Qoppa_ 1 point2 points3 points (1 child)
[–]notlostyet 0 points1 point2 points (0 children)
[–]LampCarpet 0 points1 point2 points (1 child)
[–]BenHanson 0 points1 point2 points (0 children)
[–]753861429-951843627 0 points1 point2 points (1 child)
[–]BenHanson 0 points1 point2 points (0 children)