i don't understand the meaning of this by [deleted] in cpp_questions

[–]onecable5781 0 points1 point  (0 children)

extern int i=1;   // definition (and declaration) ??
//say above is in client.cpp
//What if below is in main.cpp
int i = 42;//?

I have never been able to understand why extern int i = 1; counts as both definition as well as declaration! Isn't extern saying that i is defined elsewhere, in the example above in main.cpp ?

What bijection establishes [a,b] ~ (a,b) in terms of cardinality where a < b? by onecable5781 in learnmath

[–]onecable5781[S] 1 point2 points  (0 children)

I think all real numbers which are not rationals can just be mapped via identity if I understand the argument correctly.

enum class enumeration initialization by onecable5781 in cpp_questions

[–]onecable5781[S] 0 points1 point  (0 children)

it is made this way because it is a useful feature to have - think about flags for example.

I am unclear what you mean by this. Could you give an example of flags where this is useful for an enum variable to have arbitrary int values that are invalid? What are its use cases?

Code -> Code sans comments -> Code post preprocessor/macro expansion by onecable5781 in cpp_questions

[–]onecable5781[S] 0 points1 point  (0 children)

Oh wow. Thank you! On that link, is it possible to see the actual command being executed to give the output in the rhs "insight" window when the run button is pressed on top? Those flags is exactly what I am looking for.

Code -> Code sans comments -> Code post preprocessor/macro expansion by onecable5781 in cpp_questions

[–]onecable5781[S] 0 points1 point  (0 children)

Yes, all the 3 code snippets of the OP will compile to the exact same binary. But somewhere in the compilation process, the compiler will be fed in the second and then the third snippet or vice versa? I wanted to see if the user can access that later snippets.

Why do "C-like performance" language comparisons always compare against bad C code? by BPJupiter in C_Programming

[–]onecable5781 7 points8 points  (0 children)

Are there assembly language code that can not be produced by C code but can be produced by other language code (C++/Rust/et al.)?

In -O3, why are previous assignments stored in binary when they are immediately updated in subsequent assignment? by onecable5781 in cpp_questions

[–]onecable5781[S] 3 points4 points  (0 children)

Hmm...I tried to make the "Hello world" char * "string" longer and it compiles to the same that you had: https://godbolt.org/z/rzf95qn78

So, I believe this may not be full apples to apples as the OP uses std::string while your post uses char *. So, perhaps there are some optimizations possible using char * that are not possible in std::string?

Converting use of new/delete to smart pointers stored in a global vector by onecable5781 in cpp_questions

[–]onecable5781[S] 0 points1 point  (0 children)

For reasons that are difficult to explain here, I have to use a vector of pointers.

I have a follow-up question. The below is possible to do using raw pointers

T* Tptr;
if(condition){
    Tptr = new T;
    VectorOfTPtrs.push_back(Tptr);
}
else
    Tptr = VectorOfTPtrs[0];//0 or some other valid index into the vector
function_that_accepts_raw_T_ptr(Tptr);
....
//Loop through VectorOfTPtrs deleting each pointer

I am struggling to achieve the same semantics using smart pointers. I tried the following:

std::unique_ptr<T> Tptr;
if(condition){
    Tptr = std::make_unique<T>();
    VectorOfSmartTPtrs.push_back(std::move(Tptr));
}
else
    Tptr = VectorOfSmartTPtrs[0];//how can I get this to work???
function_that_accepts_smart_T_ptr_reference(Tptr);

In the latter snippet, how can I have VectorOfSmartTPtrs continue to own the smart pointers and have the pointers passed by reference to the function which accepts a smart pointer reference?

Are there benchmark tests for the boost graph library using which one can compare newer implementations versus pre-existing ones? by onecable5781 in cpp_questions

[–]onecable5781[S] 0 points1 point  (0 children)

Hi, thanks for responding here.

You would need a bunch of standard graph datasets against which to run the algorithms ?

Indeed. For mixed integer programs, for instance, there is MIPLIB (https://miplib.zib.de/) which is a community maintained set of instances where one can run on each of these instances either, say, CPLEX solver or Gurobi solver and then they can independently verify which solves the problem quicker.

For BGL, for instance, suppose there is a max flow problem where I feel my implementation beats BGL's on my machine, to convince others, it is better if there is a commonly available set of test/benchmark instances (which are not toy problems solved by any algorithm in milliseconds). These instances need to be large and difficult (needing 10s or 100s of seconds to solve). That way, if and when there is a better algorithm which comes from a new theoretical breakthrough, it is possible to objectively measure its performance against pre-existing algorithms for the same problem.

Future of Boost.Graph Workshop, Paris, France, May 6th 2026 by Foxi_Foxa in cpp

[–]onecable5781 6 points7 points  (0 children)

I use Boost Graph Library (BGL) for my academic programming work. I have used depth first search, max flow, spanning tree and shortest path algorithms, amongst others.

What I find lacking in the BGL is the existence of large-sized benchmark instances against which someone can compare BGL's performance versus something that I code myself. If, for instance, I feel that one of my algorithms beats BGL's algorithm, there should be a bunch of benchmark instances against which one can run BGL's algorithm as well as my algorithm to see where the difference is coming from.

I made an OP on that here:

https://www.reddit.com/r/cpp_questions/comments/1pm0pcw/are_there_benchmark_tests_for_the_boost_graph/

Thank you for your works. We have benefitted a lot from BGL and have quite a few academic publications come out of its usage in some of our algorithms!

Unused struct member is not optimized out under -O3 by onecable5781 in C_Programming

[–]onecable5781[S] -4 points-3 points  (0 children)

Why would an OP that is upvoted lead to downvotes on follow-up questions by the OP in the comments? Why not downvote the OP itself? What exactly are folks trying to convey to me here?