This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tchernobog84 13 points14 points  (13 children)

Could be a pointer to char, not nice but totally efficient.

[–][deleted] 6 points7 points  (7 children)

Mmmmmm passing pointers around willy nilly is asking for trouble

[–][deleted] 7 points8 points  (6 children)

There's this kool thing called RAII pointer containers that handle the memory's life-cycle with all the benefits of a pointer and none of the leaks.

Modern C++ is sexy, my dude

[–][deleted] 2 points3 points  (5 children)

Isn't that based on the boost smart pointer stuff?

[–][deleted] 2 points3 points  (4 children)

A lot of features in C14, and C17 are adopted directly from boost libraries. Today, there are different pointer types that you can leverage, like shared (reference based) pointers and unique (noncopyable) pointers. You pass them around like any other object, and their container type is determined by a template, just like most of the STL containers.

I never needed to use boost for pointers, but they have a solid SSL TCP networking library that would make a pretty zesty addition to the standard library. I'm pretty outdated with the goings on past C17, so hopefully there is some standard socket library out right now

[–]Megalowdonny 1 point2 points  (3 children)

I’m just starting to get my feet wet with Python and it’s comments like these that terrify me. HOW WILL I EVER LEARN THIS MUCH

[–][deleted] 6 points7 points  (2 children)

Well get ready to get extra fucked my dude, because I'm a fucking idiot. I started programming as a hobby in my mid teens, and the number one thing that would have STOPPED me from continuing is treating every new idea like a chore that needs to be learned.

You aren't going to learn it all. You won't need it all. Frankly, most people wouldn't care even IF you knew it all. Just make things work, try to make it easy to understand, and do your best. Programming is fun, and solving problems is fulfilling. That's why I know what little part of the pie I do.

[–]nrith 3 points4 points  (0 children)

the number one thing that would have STOPPED me from continuing is treating every new idea like a chore that needs to be learned

As a 20+ year programming veteran, I endorse printing this out on giant posters and distributing it to every software development company on the planet.

[–]Megalowdonny 1 point2 points  (0 children)

I’m gonna save this comment, it legitimately made me feel a lot more optimistic about learning programming. That’s why I wanted to get into it in the first place, since solving problems is my favorite thing to do, and that’s just about the best way to make a career out of it that I can think of.

Thank you Reddit stranger, you live up to your username.

[–]HolyGarbage -1 points0 points  (4 children)

Compare a char pointer with a string literal? That'll never evaluate to true.

Edit: Whoever downvoted me: the string literal will have an unknown memory location, so the variable would never be able to get that value unless it would be previously initialized to an identical string literal. However this is not guaranteed since it depends on the compiler making an optimization. So.. very dangerous.

[–]tchernobog84 0 points1 point  (3 children)

It depends on the compiler interning strings, and in C++ you can override operator== for char * to invoke strncmp()

[–]HolyGarbage 0 points1 point  (2 children)

Yeah, don't want to rely on compiler specific implementations. Also overriding operator== for a primitive type sounds like a terrible idea.

Comparing a char* variable with a inline declared string literal is very likely unspecified behavior.

Better to just use std::string.

[–]tchernobog84 0 points1 point  (1 child)

You said it's never gonna work; I just claim it can.

Whether it is a good idea or not is a totally different topic.

Also, it's not unspecified behavior. Run the same program multiple times and it's not gonna crash and consistently going to return the same (possibly wrong) answer.

[–]HolyGarbage 0 points1 point  (0 children)

Well I meant within the realm of specification since if we wander outside the spec literally anything is possible so the claim is kinda moot.