r/SubredditDrama • u/downvotes_puffins • Mar 09 '17
C programmer writes code to demonstrate an argument, includes a bug
Programmer dismisses concerns about "unsafe" code, "whatever that means".
Gets his comeuppance.
It did not go well upthread, either.
33
Upvotes
3
u/Sanae_ Mar 09 '17
AFAIK, there are no bugs (except maybe not checking
size * newcapdoesn't wrap around.`T* -> void* -> T*`` is well-defined in C.
4
u/SnapshillBot Shilling for Big Archive™ Mar 09 '17
http://imgur.com/a/JLRVN
Snapshots:
I am a bot. (Info / ^Contact)
2
u/Reachforthesky2012 You can eat the corn out of my shit Mar 10 '17 edited Mar 10 '17
Wow that guy is obnoxious. All over the thread trying to convince people how C is definitely just as useable as C++ and how there's no downside to using it, and basically demonstrates why he's wrong by making a mistake personally coding a defined function of C++ in C. Love it
2
u/tehnod Shilling for bitShekels Mar 09 '17
void *resize(void *ptr, size_t size, size_t *cap, size_t newcap) { if (*cap >= newcap) return (ptr);
ptr = realloc(ptr, size * newcap); if (ptr != NULL) *cap = newcap;
return (ptr); }
My limited understanding of Java and JavaScript gives me nothing on how this works. Is void name* how you make variables or functions or arrays? I have a headache from looking at this.
Edit- And I ruined the formatting. Fuck beans.
1
u/drvoke Mar 13 '17
Here and on stack overflow, devs jerk themselves raw over the finest minutiae in the most egotistical fashion and are often wrong or missing the point. It's like a Pep-Boys mechanic criticizing the engineering standards at Tesla.
0
u/[deleted] Mar 09 '17
[deleted] — view deleted comment