DEV Community

loading...

Discussion on: Make sense of pointers

Collapse
jmau111 profile image
Julien Maury Author • Edited

there is no typo in the article, I always use the most portable and less confusing syntax ;)
so, to me, the first one

Collapse
pentacular profile image
pentacular

So, what does this declare? :)

int* a, b;
Thread Thread
jmau111 profile image
Julien Maury Author

Is it a real question or did you find something false in the article? I'm not sure so I prefer asking you before actually answering to that.

Thread Thread
pentacular profile image
pentacular

Your claim is that "int* a;" is more portable and less confusing.

So I'm asking what "int* a, b;" does to see if you've really thought it through.

What is the type of b given this declaration?

Thread Thread
jmau111 profile image
Julien Maury Author

int *a = &b; is like int *a: and then a = &b;, IMHO int* a = &b; is less confusing.

Thread Thread
pentacular profile image
pentacular • Edited

So, given "int* a, b;" what is the type of b?

Thread Thread
jmau111 profile image
Julien Maury Author

I'm trying to use explicit things and you give me examples of "implicit" declarations, which is kinda confusing and pretty much my point. b would not have the type you might expect, you get int here. I dit not use that in the article.

I prefer splitting declarations than inlining with commas. Not saying it's the best practice, but it's less confusing, at least for me.

Thread Thread
pentacular profile image
pentacular

What's implicit about those declarations?

My point is that because "int* a, b;" has that kind of confusing behavior, it's odd to claim that you chose it because it is the least confusing syntax.

There are many good arguments for it, but least confusing doesn't seem to be one of them. :)

Thread Thread
jmau111 profile image
Julien Maury Author

it's not what I've said. I'm not inlining declarations like you. I respect your opinion, but I disagree with you here. Anyway, thanks for pointing that :) I will see if, in practice, it's handier or not, smarter or not.

Thread Thread
pentacular profile image
pentacular

By all means. :)

Forem Open with the Forem app