« first day (1540 days earlier)      last day (1304 days later) » 

3:08 AM
@CătălinaSîrbu Okay, that is what you call a K&R syntax and is prevalent in most pre-80s C codes. It is not supported by C++ though
 
 
3 hours later…
5:47 AM
yes but I can't find it in K&R book 2nd edition . :))
I was curious
 
6:40 AM
@CătălinaSîrbu You will find that syntax only in the first edition
 
 
2 hours later…
nwp
8:55 AM
@CătălinaSîrbu I see types specified and the parameter numbers match for the type list.
 
@nwp No K&R turns off typechecking and literally all safe guards
 
I mean C has no function overloading, so you really don't need to know the parameter types to call a function
 
nwp
What's the point of int n; int m; then? Is that just a comment?
 
 
2 hours later…
11:06 AM
20 messages moved from Lounge<C++>
 
 
2 hours later…
12:48 PM
Why is static_cast<in&&>(3) rvalue expression and static_cast<int&>(k) ( where k is some int variable) is lvalue expression ?
 
nwp
Which part is surprising?
3 is an rvalue and k is an lvalue. The first is cast to an rvalue reference and the second to an lvalue reference.
 
Good question. It used to be static_cast<int&&>(3), but now I'm not sure at all haha
 
nwp
What do you mean by "used to be"? That's still what the previous text says. Ignoring the missing "t" that I assume is a typo.
 
It used to be surprising that static_cast<int&&> is rvalue expression
Now I don't even know
Ok let me rephrase
Is there a way to determine whether an expression can be used as l-value using only our knowledge of C++ ?
 
nwp
Sure. Learn the required passages from the standard and apply them.
I feel like that's not the question you meant to ask.
Did you mean "Is there an easy rule to figure out if an expression is an lvalue or an rvalue"?
 
1:05 PM
Yes
Well, it doesn't have to be easy. I just want to be able to determine it.
Using only my brain without compiler telling me
 
nwp
Hmm. That's tricky because it depends on what your brain is able to do.
Usually intuitive understanding helps brains. And lvalues and rvalues are not intuitive.
Temporaries are much more intuitive. You know that behind 3 there is an int somewhere and that said int temporarily exists for the expression and then is gone.
Temporaries are rvalues.
Then there are variables that persist. Variables have a name and you can take their address. Those are your lvalues.
Though that doesn't help at all with the cast example.
 
What makes you know that static_cast<int&&>(3) is rvalue ?
To make it really simple.
What is your reasoning ?
 
nwp
Because it says `&&` which is an rvalue reference.*
*There are also forwarding references that use `&&` which are not rvalue references, but that doesn't apply here.
 
But then how do you differentiate that from expressions like int&& k = 3 ?
I mean, k is lvalue.
Can you tell me if I'm asking a dumb question ? Because if I do, I doubt anyone can help me besides me.
 
nwp
The rule for that is that you cannot take the address of temporaries. I know that &k compiles and gives me an int *, so it cannot be a temporary.
No, it's not a dumb question. It's tricky and I'm not sure I understand it right either.
 
1:15 PM
6
Q: Rvalue reference or lvalue?

domocar1I've got a question of similiar nature like this one posted 5 years ago: Why are rvalues references variables not rvalue? My major concern is why can I do this: int&& k = 3; k++; but I cannot do this: (static_cast<int&&>(3))++; I've always interpreted rvalue references as lvalues since rvalue r...

 
nwp
What is dumb is worrying about it. You don't need to know these things. Just know what a temporary is, why it matters and that std::move exists and you're good. But I'm getting the feeling you have an exam of sorts that will ask these questions so you have to know the answer.
 
Haha, nono there is no exam.
The thing is; all of these I'm asking for myself. I want to expand my C++ knowledge as far as it can get.
C++ is the only thing that interests me currently.
 
nwp
How much programming practice did you get in?
 
in c++ ?
 
nwp
Yes
You've gone way deep into theory and you need both. Maybe you should apply your knowledge a bit.
 
1:22 PM
So by now, I've had 2 C++ subjects in my uni. First one was something like beginner's c++ and the second one somewhat intermediate.
We did plenty of tasks so far
And this year I'm enlisting Advanced C++
 
nwp
Let me rephrase. Have you implemented function_view or typelists or an ECS yet?
 
I have no idea what those things are
 
nwp
Then you should probably do some exercises in that direction instead of learning about value categories that are only relevant for compiler implementers.
If you haven't looked into type erasure, reimplementing std::function is a "fun" exercise.
 
I see, I didn't have a clue this was marked as deep in theory. For the whole time I thought I was scratching the surface of it
I'll definitely think about it, thanks for the advice
 
 
5 hours later…
6:41 PM
format '%s' expects argument of type 'char *', but argument 2 has type 'char * ( * )(char *)' [-Wformat=]|
how can I solve this warning?
 
@CătălinaSîrbu call the function you're passing as the parameter
 
I dont understand how
 
so like "str.c_str()" instead of "str.c_str"
 
I'm using _Generic to overload some function
and I am somehow sure that I don't have to call the function
 
oh, C, nvm, got no clue
well, he compiler disagrees with you in any case
*the
 

« first day (1540 days earlier)      last day (1304 days later) »