Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's considered horrendous practice to typedef to a pointer of something. Not sure why this can be considered easy.


Citation needed on that, plenty of major libraries typedef pointers all the time.


I don't do much in C anymore and definitely never used a library that had a typedef'd pointer type. If I had to guess I'd imagine it's something like: variables that are pointers are syntactically different. Unless they're used "opaquly" I guess.

If I see a declaration like "Foobar baz;" I don't know which of "baz.boo", "baz->boo" or "baz[x]" are syntactically valid at a glance.

Dunno if that's a huge deal but it's all I came up with.


The thing is, even with the raw pointer the hard part is resolving ownership questions, not resolving the type. The tricky questions in C are: am I responsible for freeing it or is the library? If I send it into this function call am I transferring ownership? Type deffing doesn't make any of that easier or harder to figure out. Whether the thing is a handle or a pointer doesn't really complicate things, if that makes sense.


I get what you're saying, but I'm speculating what not type defing might help with. It's clearly advice that drifts around. Even if you think it doesn't help much it must address something for somebody, right?


Yeah. Like I remember the win 32 API (not saying it's a good API though) to typedef every struct and it's pointer. I'm not sure if the Linux API are the same though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: