r/shittyprogramming • u/2dphile • Sep 15 '16
I was debugging into our library routine and found found some complicated shiz...
13
u/Randolpho Sep 15 '16
Eh, that's too complicated for me to read.
5
u/2dphile Sep 15 '16
lol, the exact same thing had crossed my mind.
11
u/Katholikos Sep 15 '16
I've literally worked with C++ once in my life, so this might be a dumb question, but why are there two yankee doodles in "if(pN27Point->->GetCorner()"? I thought that was for accessing a member, but I'm not sure why you'd use two.
10
u/VeloCity666 Sep 15 '16
pN27 is a pointer that points to a pointer that points to the object, so you need to dereference it twice.
(**pN27Point).GetCorner()would've been equivalent (2 asterisks instead of one).
3
u/Veedrac Sep 17 '16
/r/shittyprogramming taught me something today. I've never seen
->->before, didn't think it was valid.EDIT: It's not. I've been fooled. Nice, upvotes for everyone.
2
u/Katholikos Sep 16 '16
Thanks for the explanation!
2
u/VeloCity666 Sep 16 '16
No prob! Btw just curious, are you Greek? I am and your name seems to suggest so.
3
u/Katholikos Sep 16 '16
Haha, I'm not - I just really like the Greek language. Sounds and looks really beautiful to me.
1
1
u/TPHRyan Sep 15 '16
To be extra clear and not assume knowledge of dereferencing:
In C/C++ you have "pointers", which is basically a number that references an address in memory. We have useful operators that are used to access the memory that is pointed to by pointers:
.is the operator you use to access a member of an object. You're probably used to this.
->(unlike in PHP) is the operator you use to access a member of the object this variable is pointing to, so it goes 1 step further.We don't have shorthand for "access a member of the object that is pointed to by the pointer that is pointed to by this variable", so we just use
->->to go an additional step further.1
1
u/SarahC Sep 16 '16
Wouldn't a.b() be the same as a->b().. as 'a' would be the pointer to the object in either case? 'a' being the reference to the object?
..... I know it's not that, but I don't know what I'm missing here. I'm guessing with a.b, a is the straight object name, and a->b it's a pointer to the object..... but how (or why?) would they be treated any differently?
I'm just thinking about it the same way as JavaScript first order functions or C#'s delegate variable for a function 'pointer'?
In C isn't it just & * to reference and dereference a pointer? (I thought C++ only used -> for objects?)
1
u/NasenSpray Sep 25 '16
->->is a syntax error.1
20
u/jP_wanN Sep 15 '16
Oh god, GRID_GetCenter_DLSorNTS has to be the worst function name I've ever read. And they call it function with a const_casted pointer with no comment explaining why that would be okay there. Just... Wow.
3
u/Drainedsoul Sep 16 '16
Yupp as soon as I saw
const_castit was shitty programming, nothing else needed.
8
u/DarkRonin00 Sep 15 '16
Reverse engineering a dsp board I can safely say it's worse when there are no comments....
11
u/VeloCity666 Sep 15 '16
reverse engineering
comments
Ah if only.
2
u/steamruler Sep 16 '16
Imagine the outcry if comments were suddenly compiled into executables and could be restored.
2
6
2
1
44
u/TangibleLight Sep 15 '16
I love how they left that last line half-written. Like they just realized as they were typing "this is gonna be worse than I thought" and gave up.